简体   繁体   中英

set location of dll class library which is referenced in other project in solution

I'm doing a solution which has a 3 projects(c#).

  1. Main executable project
  2. Dll
  3. Dll

Main project has references to others. I want to have following file structure in my main project:

main.exe 
Libraries - folder
  + 2.dll
  + 3.dll

But unfortunately VS is putting those DLL files to EXE location.

It there any simple solution to do it?

You can change the Output Path on the child DLLs to point to Libraries.

However, this is not a standard path that .Net probes at runtime for DLL resolution, so you will likely have issues when you try to deploy this unless you load from these locations by hand.

If you have the project reference marked to Copy Local, then I don't believe that you can change the directory that Visual Studio copies files into through configuration.

However, you could setup a post-build command that automatically moves the files into the desired subdirectory after each build.

Update

I love this site because it enables me to learn new things every day. As a case in point, I just discovered the probing element that you can add to your config file in order to add additional paths to the standard probing paths.

This configuration element allow .Net to search your libraries folder for DLLs to load so that you don't have to do any additional work once they are in place (you will still need to move them to that directory using a postbuild command).

Here is a sample config entry to support your configuration:

<configuration>
   <runtime>
      <assemblyBinding>
         <probing privatePath="bin\libraries"/>
      </assemblyBinding>
   </runtime>
</configuration>

I have the same issue, but previous examples doesn't worked. Only after i pointed the scheme, everything worked fine:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="Libraries"/>
    </assemblyBinding>
  </runtime>
</configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM