为什么要进行"bindingRedirect"操作?在添加Microsoft.Bcl.Async包后添加到app.config文件中? [英] Why is a "bindingRedirect" added to the app.config file after adding the Microsoft.Bcl.Async package?

查看:174
本文介绍了为什么要进行"bindingRedirect"操作?在添加Microsoft.Bcl.Async包后添加到app.config文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么nuget在安装Microsoft.Bcl.Async之后将以下代码添加到我的应用程序app.config文件中:

I was wondering why nuget added the following code to my applications app.config file, after installing the Microsoft.Bcl.Async:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

如果我从配置中删除此XML元素,则该应用将无法正常运行.

If I remove this XML-element from the config, the app will not work properly.

据我了解,我们可以使用bindingRedirect使应用程序加载程序集的新版本或旧版本,以防编译EXE时使用的版本消失.
但是我恰好使用的版本是2.5.19.0,那么为什么我需要重定向?

As far as I understand it, we can use the bindingRedirect to make the app load a newer or older version of an assembly in case the version we were using when compiling the EXE is gone.
However I am using exactly the version 2.5.19.0, why would I need a redirect then?

为什么需要这个bindingRedirect?

Why do I need this bindingRedirect?

推荐答案

程序集Microsoft.Threading.TasksMicrosoft.Threading.Tasks.Extensions仍引用System.RuntimeSystem.Threading.Tasks的v1.5.11.0.

The assemblies Microsoft.Threading.Tasks and Microsoft.Threading.Tasks.Extensions are still referencing v1.5.11.0 of System.Runtime and System.Threading.Tasks.

在没有bindingRedirect的情况下,Microsoft.*程序集将尝试加载旧版本的System.*程序集,该程序将失败.

Without the bindingRedirect, the Microsoft.* assemblies would try to load an old version of the System.* assemblies, which would fail.

这篇关于为什么要进行"bindingRedirect"操作?在添加Microsoft.Bcl.Async包后添加到app.config文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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