问题
I have a project where I would want to use some specific version of a dll.
The GAC contains couple of versions of that dll (new & old), I would want to use the old when running the program.
Issue is that the newest dll is always picked-up from the GAC.
Would you know if there is a way to either:
- Force the usage the dll that is in the run folder (the one I'm referencing in my solution, working fine in debug).
- Force the usage of the old version of the dll from the GAC.
Thank you!
回答1:
When you have added the library to your project and you collapse the 'References'-node of the project tree, you'll see the added library. When you select it and click the 'Properties'-node of the context menu, you can specify if a specific version of the library should be used and which version to use. Simply set 'Specific Version' to true and specify the Version number. Then you don't have to cope with the question where the version you want is loaded from.
回答2:
Have you try to "Redirecting Assembly Versions" in your app.config? http://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx
回答3:
Took me forever to figure this out but what I did was on the "Reference Paths" I added the exact path to the old DLL's then made that the first place to check. It then pulled the old versions which is what I needed for Crystal Reports. We have multiple applications that use 13.0.2 but I develop in Visual Studio 2017. I was able to install the latest Crystal Reports add-in for VB, 13.0.23, but reference the old 13.0.2 using this method.
回答4:
You can use a binding redirect
in your app.config or web.config in the runtime
node:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Make sure you have the correct publicKeyToken
and know which versions you want to redirect to what version.
(You can check a publicKeyToken
of a DLL
like this with this info.)
MSDN Documentation
You can also generate these for an entire solution using the Package Manager Console
Get-Project -All | Add-BindingRedirect
This will update all app.config
files and add the binding redirect.
来源:https://stackoverflow.com/questions/25131753/use-a-specific-version-of-a-dll-in-c-sharp