升级C#项目中的引用dll而不重新编译项目 [英] Upgrade a reference dll in a C# project without recompiling the project

查看:366
本文介绍了升级C#项目中的引用dll而不重新编译项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用C#应用程序的内置版本,并更改​​其中的一个参考文件。什么是最好的方式来做到这一点,我有特定的版本关闭参考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?

推荐答案

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

Yes, you can do this - see the MSDN article Redirecting Assembly Versions.

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

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>

几个注释:


  • 如果您没有明确指定
    您的文化(尽可能多),则
    将为中立而不是en-us。

  • If you haven't explicitly specified your culture (as many don't), it will be "neutral" rather than "en-us".

如果您还不了解,可以使用强名称实用程序
获取程序集的公钥令牌
,如
这样: sn -t [AssemblyPath]

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆