我有一个项目,我想在其中使用某个特定版本的 dll。
GAC 包含该 dll 的几个版本(新的和旧的),我想在运行程序时使用旧的。
问题是最新的 dll 总是从 GAC 获取。
你知道是否有办法:
- 强制使用运行文件夹中的 dll(我在我的解决方案中引用的那个,在调试中运行良好)。
- 从 GAC 强制使用旧版本的 dll。
谢谢!
最佳答案
您可以在 runtime
节点的 app.config 或 web.config 中使用 binding redirect
:
<?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>
确保你有正确的 publicKeyToken
并且知道你想将哪个版本重定向到哪个版本。
(您可以使用 this info 检查 DLL
的 publicKeyToken
。)
您还可以使用 Package Manager Console
Get-Project -All | Add-BindingRedirect
这将更新所有 app.config
文件并添加绑定(bind)重定向。
关于c# - 在 C# 中使用特定版本的 dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25131753/