为什么是“bindingRedirect"?添加 Microsoft.Bcl.Async 包后添加到 app.config 文件? [英] Why is a "bindingRedirect" added to the app.config file after adding the Microsoft.Bcl.Async package?

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

问题描述

我想知道为什么在安装 Microsoft.Bcl.Async 后,nuget 将以下代码添加到我的应用程序 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 仍在引用 v1System.RuntimeSystem.Threading.Tasks 的 .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.

如果没有 bindingRedirectMicrosoft.* 程序集会尝试加载旧版本的 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天全站免登陆