程序集绑定重定向:如何以及为什么? [英] Assembly Binding redirect: How and Why?

查看:80
本文介绍了程序集绑定重定向:如何以及为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是问题问题,而是有关程序集绑定重定向工作的一般理解问题。

This is not a problem question but a general understanding question on assembly binding redirect's working.

查询


  1. 为什么绑定重定向仅显示主要版本而不显示次要版本和版本号?

  2. 新旧版本兼容吗?

  1. Why binding redirect shows only major version and not minor, build and revision numbers?
  2. Does old and new version change only when there is change in major version?

<dependentAssembly>
    <assemblyIdentity name="FooBar"  
                      publicKeyToken="32ab4ba45e0a69a1"  
                      culture="en-us" />  

    <bindingRedirect oldVersion="7.0.0.0" newVersion="8.0.0.0" />  
</dependentAssembly>



推荐答案

为什么根本需要绑定重定向?假设您有引用库B的应用程序A,还有版本1.1.2.5的库C。库B依次也引用库C,但版本为1.1.1.0。现在我们有了冲突,因为您不能在运行时加载同一程序集的不同版本。要解决此冲突,您可以使用绑定重定向,通常是重定向到新版本(但也可以是旧版本)。为此,您可以在 configuration>下将以下内容添加到应用程序A的app.config文件中。运行时> assemblyBinding 部分(请参见此处作为完整配置文件的示例):

Why are binding redirects needed at all? Suppose you have application A that references library B, and also library C of version 1.1.2.5. Library B in turn also references library C, but of version 1.1.1.0. Now we have a conflict, because you cannot load different versions of the same assembly at runtime. To resolve this conflict you might use binding redirect, usually to the new version (but can be to the old too). You do that by adding the following to app.config file of application A, under configuration > runtime > assemblyBinding section (see here for an example of full config file):

<dependentAssembly>
    <assemblyIdentity name="C"  
                      publicKeyToken="32ab4ba45e0a69a1"  
                      culture="en-us" />  

    <bindingRedirect oldVersion="1.1.1.0" newVersion="1.1.2.5" />  
</dependentAssembly>

您还可以指定要映射的版本范围:

You can also specify a range of versions to map:

<bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.2.5" />  

现在参照版本1.1.1.0的C编译的库B将使用版本C 1.1.2.5在运行时。当然,您最好确保库C向后兼容,否则可能导致意外结果。

Now library B, which was compiled with reference to C of version 1.1.1.0 will use C of version 1.1.2.5 at runtime. Of course, you better ensure that library C is backwards compatible or this might lead to unexpected results.

您可以重定向任何版本的库,而不仅仅是主要版本。

You can redirect any versions of libraries, not just major ones.

这篇关于程序集绑定重定向:如何以及为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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