同一個解決方案或有依賴關系的兩個項目引用同名但不同版本的DLL
阿新 • • 發佈:2017-06-07
web bind 節點 20px 博客 fig 朋友 ase 方案
問題描述
我們最近在使用Redis作Session的集中化,中間碰到了一個如下問題:我們有一些項目比較老,引用了NewtonJson的4.0.3.0版本的DLL,但是Redis提供的C#集成DLL引用的是NewtonJson的7.0.0.0版本的DLL,但我們要在老項目中引用Redis集成DLL,因而就碰到了NewtonJson的版本沖突問題。
解決方案一
我們可以通過配置web.config(或者app.config)來幫助我們解決這個問題。需要在web.config中配置如下節點:
1 <runtime>
2 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
3 <dependentAssembly>
4 <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
5 <codeBase version="4.0.3.0" href="C:\v2.0\Newtonsoft.Json.dll" />
6 <codeBase version="7.0.0.0" href="C:\v3.5\Newtonsoft.Json.dll" />
7 </dependentAssembly>
8 </assemblyBinding>
9 </runtime>
說明1:有的朋友博客上面說,需要在主項目中引用最新版本的DLL,經過實驗是不需要這樣做的。
說明2:name填程序集的名稱,pulicKeyToken是數字簽名,version是程序集的版本,href指不同版本的程序集的地址,我嘗試過,無法使用相對路徑,必須使用絕對路徑,可能使用相對路徑也可以,但需要另外的配置,如果有朋友知道,麻煩分享一下。
解決方案二
如果在同一個項目中引用不同版本的DLL,但新版本的DLL兼容舊版本的DLL,那麽可以采用如下的配置:
1 <runtime>
2 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
3 <dependentAssembly>
4 <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
5 <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
6 </dependentAssembly>
7 </assemblyBinding>
8 </runtime>
參考文檔
http://www.cnblogs.com/EugeneMay/p/4249709.html
http://bbs.csdn.net/topics/390359027
同一個解決方案或有依賴關系的兩個項目引用同名但不同版本的DLL