2016-05-12 79 views
1

我正在寫一個Asp.Net 5(MVC6)web api,並且添加了nuget包「SharpMap」,它依賴於Newtonsoft.Json v4.5.0.0,但是組件Mvc .Asp.Net.Mv.ViewFeatures需要Newtonsoft.Json v6.0.0.0。如何繞過nuget版本限制

如果我更新Newtonsoft.Json到V6或更高版本,我得到這個錯誤:

Assembly 'Microsoft.AspNet.Mvc.ViewFeatures' with identity 'Microsoft.AspNet.Mvc.ViewFeatures, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' uses 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' which has a higher version than referenced assembly 'Newtonsoft.Json' with identity 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

如何繞過的NuGet包的版本restriccion任何想法?或者針對這個特定問題的其他解決方案?

回答

1

您可以在安裝過程中使用-IgnoreDependencies標誌來讓NuGet自己安裝軟件包,而不用擔心依賴衝突。在這種情況下,這聽起來像你想卸載SharpMap中,安裝一切(包括Json.NET 6),然後運行:

Install-Package SharpMap -IgnoreDependencies 

然後,我們必須使.NET不抱怨的版本衝突在運行時。這可以通過添加一個binding redirect到你的web.config /的app.config文件來完成:

<configuration> 
    <runtime> 
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
      <assemblyIdentity name="NewtonSoft.Json" /> 
      <bindingRedirect oldVersion="4.0.0.0-6.0.0.0" 
          newVersion="6.0.0.0"/> 
     </dependentAssembly> 
     </assemblyBinding> 
    </runtime> 
</configuration> 

這告訴運行時將請求重定向到負載Json.NET 4-6加載Json.NET 6.注意這裏使用的版本是.NET程序集版本,與NuGet程序包版本不一樣!

但是,像SharpMap這樣的軟件包在像NewtonSoft.Json這樣的通用第三方庫上綁定了嚴格的版本是很奇怪的。考慮要求維護者提供一個只具有該依賴關係下限的版本(例如4.5.11或更高版本)。

+0

我最終創建了一個新的slution並移植了相關的代碼。我還下載了最新的資源,並編譯了他們改變牛頓軟件的參考版本。但是你的解決方案是可行的。我會聯繫SharpMap發佈者,因爲nuget發佈的版本是3年前的版本,但來源只有3個月的時間。 –