0

I've got a windows application project that builds in an exe that uses a DLL (RestSharp). The project is in Visual Studio 2008. I've added the DLL in the References and if I click on the DLL i see:

  • aliases: global
  • copy local: true
  • specific version: false
  • Path: C:\Dev\MyProject\Lib\Restsharp.dll

With these settings when I build my exe, the DLL lib is copied in the build dir. On my deployment environment I'd like to have my exe in a folder and the DLL in a different one Example: C:\Test\Exe (EXE FOLDER) C:\Test\Lib (DLL FOLDER)

Is that possible? How?

I've set C:\Test\Lib in my Reference Paths, but that's an absolute path, I was looking for a relative one. Also the DLL path in References is absolute. What am I doing wrong? I'd like the exe to "find" the DLL no matter where it is copied (C:\Test or D:\Test or just D:)

Thank you

Danilo7
  • 47
  • 9

2 Answers2

0

Better you register that DLL in GAC, one DLL from same path will be using, Please refer below to know https://www.c-sharpcorner.com/UploadFile/dacca2/register-your-assembly-in-gac-using-gacutil-exe/

Rajanikant Hawaldar
  • 314
  • 1
  • 5
  • 12
0

Before starting, take a deep breath and determine exactly why you want this, because often this complicates things without much gain.

You can do this by using assembly probing.

First, its a good thing to read this firts: https://learn.microsoft.com/en-us/dotnet/framework/deployment/how-the-runtime-locates-assemblies

somewhere in the article is this:

The privatePath attribute of the element, which is the user-defined list of subdirectories under the root location. This location can be specified in the application configuration file and in managed code using the AppDomainSetup.PrivateBinPath property for an application domain.

And we can see how its done in the docs of the probing tag; https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/probing-element

Add an app.config file to your project and edit it like so:


<configuration>  
   <runtime>  
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
         <probing privatePath="bin\REEE;someTestPath"/>  
      </assemblyBinding>  
   </runtime>  
</configuration>  

Now, when the dll is added as a reference, its automatically copied to your output folder. We however want the dll to be in the subfolder instead. There're two ways you can do this that i know of;

  1. Copy the dll over from the output directory to your subpath. You can use a post-build task and e.g. xcopy to do this (google around this shouldn't be hard). You could also use msbuild tasks to copy the dll
  2. Add the dll as content to a samely named subfolder in the csproj, set to copy local. See the picture below. enter image description here

Also check this relating answer:

https://stackoverflow.com/a/58124935/4122889

I highly suggest you don't do this unless you have a very good reason to do so. And at that point i'm curious as to what that reason is :)

sommmen
  • 6,570
  • 2
  • 30
  • 51
  • First of all thank you. I want to do it because another LIB i built is already using RestSharp and it is deployed in C:\Test\Lib. The exe is going to C:\Test\Exe and I would like to avoid having 2 copies of the same DLL in 2 folders – Danilo7 Apr 21 '20 at 08:32
  • @Danilo7 hold on - that's the way its supposed to work! whenever you install an app you get all the dlls needed for it to run, aside from system dlls. just browse through your program files or something, there are tons of 'duplicate' dlls and this is normal behaviour. Why do you go against this and why do you not want 2 copies of the same dll in other folders? i assure you that there will be more than one of the same dll on your computer – sommmen Apr 21 '20 at 08:49
  • I know that's a common thing. But that made deployment a little more complicated. That's why I wanted to keep the DLLs in the same folder avoiding double copies – Danilo7 Apr 21 '20 at 09:08