【问题标题】:Why is a "bindingRedirect" added to the app.config file after adding the Microsoft.Bcl.Async package?为什么在添加 Microsoft.Bcl.Async 包后在 app.config 文件中添加了“bindingRedirect”?
【发布时间】:2013-05-30 23:58:15
【问题描述】:

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

<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 元素,应用程序将无法正常运行。

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

为什么我需要这个bindingRedirect

【问题讨论】:

    标签: c# .net app-config base-class-library


    【解决方案1】:

    您只是说,只要有 0.0.0.0 到 2.5.19.0 之间的旧版本,请将该版本替换为 2.5.19.0 的新版本

    假设您的项目中没有可用的旧版本并且您正在尝试访问它,那么您最终会遇到类似“System.IO.FileLoadException:'无法加载文件或程序集”这样的错误

    因此,当您的项目正在寻找该 DLL 的旧版本时,它会简单地将其替换为可用的新版本

    【讨论】:

      【解决方案2】:

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

      没有bindingRedirectMicrosoft.* 程序集将尝试加载旧版本的System.* 程序集,这会失败。

      【讨论】:

      • 我有类似的情况,重定向的程序集根本没有在其他地方使用,但仍然需要绑定重定向? -- 或者我可以断言,如果旧版本的程序集没有在任何地方引用,那么根本不需要绑定重定向。
      猜你喜欢
      • 2010-11-16
      • 2013-04-07
      • 1970-01-01
      • 1970-01-01
      • 2018-10-15
      • 1970-01-01
      • 2011-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多