Reputation: 15928
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?
Upvotes: 11
Views: 7337
Reputation: 40393
Depending on your audience (if this is a server app, website, desktop app for a single user, desktop app for many users, etc.), you may be able to cheat a little and host one version in a totally separate app domain, like a web service or WCF service.
For example, assuming your project is a web application:
MyWebApplication
- DLL reference to MyLibrary v1.0
- Only have internal references which use v1.0 of the library
- WCF proxy to http://localhost/MyWebService
MyWebService
- DLL reference to MyLibrary v2.0
- Only have internal references which use v2.0 of the library
Upvotes: 0
Reputation: 4851
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.
Upvotes: 4