Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi, I want to add a reference to a dll library in a c# assembly, vs2005. The problem is, I don't want it to copy to the folder of the executable (Copy Local -> false, I know) and I want it to be in a specific folder.

Example: In project myProgram (-> myProgram.exe, located for example at "c:\SomePrograms\myProgram\" - or anywhere else) I want to add a reference to library "CommonUtils.dll" that is ALWAYS located in "c:\ourCommonLibs\", and I want to access it right there (no local copy and no dynamic linking and no relative path, thank you).

Is there a way to do that?
Posted
Comments
PumbaPumba 27-Sep-10 12:06pm    
Installing your common Libs to GAC might be a solution.

Give dll a strong name and install it in GAC(Global Assembly Cache)... This would fix the location and no relative path needed.
 
Share this answer
 
Comments
Longshanx 27-Sep-10 15:23pm    
Well, yes, I could do that. But is there another way?
I think if you place the dlls in the same folder it will work as it is. Otherwise application copies the related dlls to its own folder.

I think the best workaround is not to reference the dll altogether. Rather use System.Reflection to load the dll dynamically from the other one. This will let you use Relative address for referencing the dll.

Use

Assembly.Load

Read this :
http://support.microsoft.com/kb/837908[^]
 
Share this answer
 
First of all, do not assume that there must be a C:\ drive on the computer. Make your "common dlls path" configurable.
Next, load the dlls via reflection (myAssembly = System.Reflection.Assembly.LoadFrom(path)), then instantiate the required classes (myAssembly.CreateInstance(...)). You may need to load referenced assemblies (AssemblyName[] referenced = myAssembly.GetReferencedAssemblies()).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900