nulastudio / NetBeauty2

Move a .NET Framework/.NET Core app runtime components and dependencies into a sub-directory and make it beauty.
MIT License
419 stars 21 forks source link

Force the app to use the dll in Libraries even if they exist in the root folder #56

Closed julienGrd closed 8 months ago

julienGrd commented 1 year ago

Hello guys, i met a problem with your library when i deploy my new version re-packaged with it on the server of my clients. I have a program which update all the files of my app, so with the new version he will copy all the dlls in the libraries sub folder

So when my program start after first update, it will have this files architecture |Root\ ||||||Mydll1.dll//these are the old dll, they are not supposed to be here but the program which update don't delete existing files ||||||Mydll2.dll ||||||||Libraries\ ||||||||||||Mydll1.dll//these are the new dll ||||||||||||Mydll2.dll

I manage inside my app to clean the root directory when it start because these dll are no longer in the root

But it seem, when these dll are present in the root, it use it rather than take it in the libraries folder

so i have these two problems :

So the question, is there is a way when my app start to force take the dll in the libraries folder even if they exist in the root ?

thanks !

liesauer commented 1 year ago

for native dll

you can force the search path to whatever you want by using DllImport("Libraries/Mydll1.dll")

for managed dll

to be honest, i don't have a good idea either, since those dlls may be preloaded by the corehost before the app be inited.

but you can try this

  1. open the *.runtimeconfig.json with any text editor
  2. find the NetBeautyLibsDir config, the value is supposed to be something like this: .;./libraries, try moving . to the end and becomes ./libraries;.
  3. save the file and start the app
julienGrd commented 1 year ago

In my case it was the managed dll, Your solution work perfectly, thanks for the help !

julienGrd commented 1 year ago

I don't know why but since the last update, the solution provided not work anymore (when i put "NetBeautyLibsDir": "libraries;.", it load first the dll at the root because when i want to delete them it say it impossible because its in use).

can you check that ?

thanks !

liesauer commented 1 year ago

can you post a testcase so i can check on it? i made a test but it works as expected.

julienGrd commented 1 year ago

you can reproduce it with this project https://github.com/julienGrd/BlazorAppTestNetBeautyWithPdb

liesauer commented 1 year ago

i can confirm that it's a bug of 2.1.3.4+, no clue of why ManagedAssemblyResolver is not be invoked

liesauer commented 1 year ago

you can use the v2.1.3.4 package, this version still works with the pdb moving fix.

liesauer commented 1 year ago

i will leave this issue open until figuring out why it's broken.

julienGrd commented 8 months ago

Hello ! Is there any progress on this ?

liesauer commented 8 months ago

sorry that did not respond in time, i am having the Lunar New Year holidays recently.

this issue has been fixed in v2.1.4.4.

  1. reference the latest version and add <BeautyNoRuntimeInfo>True</BeautyNoRuntimeInfo> to your csproj.

    
    <PropertyGroup>
    <BeautyNoRuntimeInfo>True</BeautyNoRuntimeInfo>
    </PropertyGroup>
    
    <ItemGroup>
    <PackageReference Include="nulastudio.NetBeauty" Version="2.1.4.4" />
    </ItemGroup>
  2. modify NetBeautyLibsDir into libraries;. in the runtimeconfig.json file.
  3. then the app wouldn't load the dll at the root first anymore.
julienGrd commented 8 months ago

perfect it work, thanks for your help !

liesauer commented 8 months ago

that's good.