2013-06-04 49 views
41

我想知道爲什麼的NuGet下面的代碼添加到我的應用程序app.config文件,安裝後Microsoft.Bcl.Async爲什麼在添加Microsoft.Bcl.Async包之後將「bindingRedirect」添加到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,爲什麼我需要重定向呢?

the version of my dll

爲什麼爲什麼要用這種bindingRedirect

回答

36

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

沒有bindingRedirectMicrosoft.*程序集會嘗試加載老版本的System.*程序集,這會失敗。

+1

我有類似的情況,其中重定向的程序集沒有使用其他地方,但仍然需要bindingredirect嗎? - 或者我可以斷言,如果程序集的舊版本沒有被引用,那麼綁定重定向根本就不需要。 – zinking

4

你只是說,只要有舊版本是0.0.0.0 之間2.5.19.0,請使用新版本是2.5.19.0

比方說,你替換版本沒有在您的項目中可用的舊版本,並且您正在嘗試訪問它,那麼最終會出現像「System.IO.FileLoadException:'無法加載文件或程序集的錯誤」

因此,當您的項目正在尋找該DLL的舊版本,它將簡單地替換該wi第三個新的可用

相關問題