Gam*_*ing 47 .net c# app-config base-class-library
我想知道为什么nuget app.config在安装以下代码后将以下代码添加到我的应用程序文件中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>
Run Code Online (Sandbox Code Playgroud)
如果我从配置中删除此XML元素,该应用程序将无法正常工作.
据我所知,我们可以使用它bindingRedirect来加载一个新版本或旧版本的程序集,以防我们在编译EXE时使用的版本消失.
但是我正在使用的版本2.5.19.0,为什么我需要重定向呢?

我为什么需要这个bindingRedirect?
Ric*_*ing 42
该组件Microsoft.Threading.Tasks和Microsoft.Threading.Tasks.Extensions仍然引用的v1.5.11.0 System.Runtime和System.Threading.Tasks.
如果没有bindingRedirect,Microsoft.*程序集将尝试加载旧版本的System.*程序集,这将失败.
小智 8
您只是在说旧版本介于0.0.0.0到2.5.19.0之间时,请将该版本替换为2.5.19.0的新版本
假设您的项目中没有可用的旧版本,并且您尝试访问它,那么您最终会收到类似"System.IO.FileLoadException:'无法加载文件或程序集"的错误
因此,当您的项目正在寻找该DLL的旧版本时,它将简单地将其替换为可用的新版本