无需重新编译项目即可升级C#项目中的引用dll

编程入门 行业动态 更新时间:2024-10-27 08:40:15
本文介绍了无需重新编译项目即可升级C#项目中的引用dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要采用 C# 应用程序的构建版本并更改其中一个参考 dll.最好的方法是什么,我在参考 dll 上关闭了特定版本,但是一旦我测试用较新版本替换 dll,我就会得到无法加载文件或程序集 XXXXX,版本 = XXXXX.是有没有办法阻止加载程序关心 dll 的版本,这样 dll 就会尝试加载?

解决方案

是的,您可以这样做 - 请参阅 MSDN 文章 重定向程序集版本.

您应该阅读整个文档,但它本质上涉及程序集的发布者创建发布者策略文件"或消费者将 bindingRedirect 添加到 app.config文件,像这样(直接从文章中复制):

<预><代码><配置><运行时><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><从属程序集><assemblyIdentity name="myAssembly"publicKeyToken="32ab4ba45e0a69a1"文化=en-us"/><bindingRedirect oldVersion="1.0.0.0"newVersion="2.0.0.0"/></dependentAssembly></assemblyBinding></运行时></配置>

一些注意事项:

如果您没有明确指定你的文化(很多人没有),它会保持中立"而不是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 specified your culture (as many don't), it will be "neutral" rather than "en-us".

If you don't already know it, you can get the assembly's public key token using the strong name utility, like this: sn -t [AssemblyPath]

这篇关于无需重新编译项目即可升级C#项目中的引用dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 21:06:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/813755.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   dll

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!