Referencing dlls without copying them C#

2.6k Views Asked by At

When we create a new C# project and reference a dll, the dll is copied to the project's output directory when compiling the project.

Is there a way of referencing dll files and not copying them to the project's output directory, and have the executable work with them when it is being run (something like Assemblies if I'm not mistaken)?

I tried accessing the reference dll's properties, and changed the Copy Local to False but it didn't help (probably because that dll is depending on other dlls located in the dll's directory).

Is there any way of doing that?

1

There are 1 best solutions below

5
On BEST ANSWER

Actually you can have you assemblies copied to GAC but this is not always an ideal solution.

You have to remember that each assembly copied to the GAC has to be strong named. If your projects uses some NuGet packages it would be a problem to install all those packages into GAC. I believe it is not a purpose of using NuGet either.

Another option would be loading your DLLs from different directory that default bin folder using <codeBase> tag in you configuration:

<configuration>
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <dependentAssembly>
        <assemblyIdentity name="MyAssembly2"  culture="neutral" publicKeyToken="307041694a995978"/>
        <codeBase version="1.0.1524.23149" href="FILE://C:/Myassemblies/MyAssembly2.dll"/>
     </dependentAssembly>
  </assemblyBinding>
</runtime>
</configuration>

but as I remember it is possible during runtime.

EDIT: Since your problem is that you have to refer SDK, which is under development, I think neither GAC nor codeBase will work. One thing is versioning problem(you have to refer to the specific SDK version), the other is that you should always recompile your tool after new SDK release because some metadata are stored in your assembly, which can be outdated with the new SDK version.