问题描述
我需要采用 C# 应用程序的构建版本并更改其中一个参考 dll.最好的方法是什么,我在参考 dll 上关闭了特定版本,但是一旦我测试用较新版本替换 dll,我就会得到无法加载文件或程序集 XXXXX,版本 = XXXXX.是有没有办法阻止加载程序关心 dll 的版本,这样 dll 就会尝试加载?
是的,您可以这样做 - 请参阅 MSDN 文章 重定向程序集版本.
您应该阅读整个文档,但它本质上涉及程序集的发布者创建发布者策略文件"或消费者将 bindingRedirect
添加到 app.config
文件,像这样(直接从文章中复制):
一些注意事项:
如果您没有明确指定你的文化(很多人没有),它会保持中立"而不是en-us".
如果你还不知道,你可以获取程序集的公钥令牌使用强名称实用程序,例如这:
sn -t [AssemblyPath]
I need to take a built version of an C# application and change one of the reference dll's. What is the best way to do this, I have specific version turned off on the reference dll but as soon as I test replacing the dll with a newer version, I get the "Could not load file or assembly XXXXX, Version=XXXXX. Is there a way to stop the loader from caring about the version of the dll so the dll will just attempt to load?
Yes, you can do this - see the MSDN article Redirecting Assembly Versions.
You should read the whole document, but it essentially involves either the assembly's publisher creating a 'publisher policy file' or the consumer adding a bindingRedirect
to an app.config
file, like this (copied directly from the article):
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="en-us" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
A few notes:
If you haven't explicitly specifiedyour culture (as many don't), it willbe "neutral" rather than "en-us".
If you don't already know it, you canget the assembly's public key tokenusing the strong name utility, likethis:
sn -t [AssemblyPath]
这篇关于无需重新编译项目即可升级C#项目中的引用dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!