Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two versions of the same dll in different projects

Tags:

.net

enter image description here

I have a solution with multiple projects. There is a need that I have to refer a different version of the same assembly in two different projects. As of now what is happening is that only the latest version of the dll is getting copied into the bin folder. So the dll that depends on the older version fails with an error

Could not load file or assembly xxxx or one of its dependencies.
The located assembly's manifest definition does not match the 
assembly reference.

Is there a way to get the application to use a specific version of dll based on the project?

like image 419
developer747 Avatar asked Jul 30 '13 18:07

developer747


People also ask

How do I use two versions of the same DLL in the same project?

config. Under <runtime> , add a <codeBase> tag for each version of the DLL. This will resolve the runtime assembly loading conflict. That's it, now we can use both versions as we please.

Can multiple versions of the assembly can live side by side?

Because the strong-named assembly's version number is part of its identity, the runtime can store multiple versions of the same assembly in the global assembly cache and load those assemblies at run time.

How do I use DLL in another project?

Solution 1Add a reference to the DLL directly to your new project: open your project in VS, expand the Project branch in the Solution explorer, then right click "References". From the context menu, select "Add Reference..." and wait for the dialog - If can take a little while to appear.


1 Answers

Yes, you can have each project reference a specific version of the same dll. I would suggest putting both versions of the dll in the GAC. In your referencing projects set the Copy Local = false and Specific Version = true.

You could do it without the GAC by using your config file and assembly binding directives (since the shared dlls can't be in the same folder because they have the same name) but this is one of the main problems the GAC was designed to solve. So I would recommend taking advantage of it.

like image 55
Russell McClure Avatar answered Oct 11 '22 12:10

Russell McClure