[英]Why is a “bindingRedirect” added to the app.config file after adding the Microsoft.Bcl.Async package?
I was wondering why nuget added the following code to my applications app.config
file, after installing the Microsoft.Bcl.Async
: 我想知道为什么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>
If I remove this XML-element from the config, the app will not work properly. 如果我从配置中删除此XML元素,该应用程序将无法正常工作。
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. 据我所知,我们可以使用
bindingRedirect
使应用程序加载程序集的新版本或旧版本,以防我们在编译EXE时使用的版本消失。
However I am using exactly the version 2.5.19.0
, why would I need a redirect then? 但是我使用的是
2.5.19.0
版本,为什么我需要重定向呢?
Why do I need this bindingRedirect
? 为什么我需要这个
bindingRedirect
?
The assemblies Microsoft.Threading.Tasks
and Microsoft.Threading.Tasks.Extensions
are still referencing v1.5.11.0 of System.Runtime
and System.Threading.Tasks
. 程序集
Microsoft.Threading.Tasks
和Microsoft.Threading.Tasks.Extensions
仍然引用System.Runtime
和System.Threading.Tasks
v1.5.11.0。
Without the bindingRedirect
, the Microsoft.*
assemblies would try to load an old version of the System.*
assemblies, which would fail. 如果没有
bindingRedirect
, Microsoft.*
程序集将尝试加载旧版本的System.*
程序集,这将失败。
You are simply saying whenever there is older version that is between 0.0.0.0 to 2.5.19.0 , please replace that version with the new version that is 2.5.19.0 您只是在说旧版本介于0.0.0.0到2.5.19.0之间时,请将该版本替换为2.5.19.0的新版本
Let's say you don't have the older version available in your project and you are trying to access it, then you will end up with an error like "System.IO.FileLoadException: 'Could not load file or assembly" 假设您的项目中没有可用的旧版本,并且您尝试访问它,那么您最终会收到类似“System.IO.FileLoadException:'无法加载文件或程序集”的错误
So when your project is looking for an older version of that DLL it will simply replace that with new one which is available 因此,当您的项目正在寻找该DLL的旧版本时,它将简单地将其替换为可用的新版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.