2016-08-22 168 views
2

我有一個使用Newtonsoft.Json版本8.0.3(nuget包含對8.0.3 Json dll的引用)構建的定製nuget包(我們稱之爲Custom.SDK)。衝突的Newtonsoft.Json nuget版本。

我的project.json文件最初使用8.0.3.0,但是在將我的項目升級到.NET Core 1.0之後,我被告知其中一個軟件包需要Newtonsoft.Json 9.0.0.0 - 因爲這樣我更新了我的項目。 json引用9.0.1(Custom.SDK仍然使用8.0.3 dll)。

現在,當我嘗試建立我的項目,我得到以下錯誤:

'Microsoft.AspNetCore.Mvc.Formatters.Json' with identity 
Microsoft.AspNetCore.Mvc.Formatters.Json, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=adb9793829ddae60' uses 
'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' 
which has a higher version than referenced assembly 
'Newtonsoft.Json' with identity 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' 

這聽起來像問題是,我的Custom.SDK的NuGet使用Newtonsoft.Json的舊版本,而我的project.json引用了新的(我需要升級到.NET Core 1.0)。

是否有可能解決此問題而不更新Custom.SDK中的JSON DLL?

回答

4

使用舊版本,當新的一個是在運行時加載編譯依賴二進制的典型情況下,你應該能夠在App.config使用BindingRedirect來解決,具體如下:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
      <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
      <bindingRedirect oldVersion="8.0.0.0" newVersion="9.0.0.0" /> 
     </dependentAssembly>   
    </assemblyBinding> 
</runtime> 

這將確保在運行時它會請求版本8.0.0.0,它會自動重定向到已經加載的9.0.0.0,請確保版本號和其他信息如Public Key token是正確的,在這裏閱讀更多關於Binding Redirect