升级 C# 项目中的参考 dll,无需重新编译项目

发布于 2024-08-05 00:51:29 字数 155 浏览 2 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尬尬 2024-08-12 00:51:29

是的,您可以执行此操作 - 请参阅 MSDN 文章 重定向程序集版本

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

<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>

一些注释:

  • 如果您没有明确指定
    你的文化(很多人没有),它会
    是“中立”而不是“en-us”。

  • 如果你还不知道,你可以
    获取程序集的公钥令牌
    使用强名称实用程序,例如
    this: sn -t [AssemblyPath]

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]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文