我有一個Visual Studio項目。
它需要Newtonsoft.Json庫。
它被Visual Studio 2017的NuGet包管理器引用。 其實10.0.3版本。.Net NuGet包衝突 - DLL地獄回來了
該項目引用NuGet包LibA和LibB。
LIBA使用Newtonsoft.Json版本8和這在package.nuspec定義:
<dependency id="RestSharp" version="105.2.3" />
<dependency id="Newtonsoft.Json" version="8.0.3" />
<dependency id="CommonServiceLocator" version="1.3" />
LibB使用NewtonSoft.Json版本10及這在package.nuspec定義:
<dependency id="RestSharp" version="105.1" />
<dependency id="Newtonsoft.Json" version="10.0.3" />
當我使用Visual Studio 2017的NuGet包管理器(在解決方案上) 更新LibA包(例如從版本1.1到1.2)時,它在.csproj文件中更新了LibA包的引用:
- <HintPath>..\packages\LibA.1.1\lib\net40\MyService.dll</HintPath>
+ <HintPath>..\packages\LibA.1.2\lib\net40\MyService.dll</HintPath>
,但它也更新Newtonsoft.Json庫的參考:
- <Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
- <HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
+ <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>..\packages\LibA.1.2\lib\net40\\Newtonsoft.Json.dll</HintPath>
和應用程序/ web.config文件:
- <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
+ <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
它還更新正確的力霸參考package.config:
- <package id="LibA.MyService" version="1.1" targetFramework="net45" />
+ <package id="LibA.MyService" version="1.2" targetFramework="net45" />
但是離開WRONG ref erence到Newtonsoft.Json庫版本:
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net47" />
我抱怨兩件事:
如果我打開的NuGet包管理器則顯示出我使用的Newtonsoft.Json版本10.0.3在當前項目中:
這不是真實的,因爲當我在bin文件夾中構建解決方案時,它存儲的版本爲8.0.3 ,並且不能更新Newtonsoft.Json,因爲它「已經」更新。
而且我的項目和LibB需要的vesion 10實際使用版本8我無法決定自動保持10版,其實我有合併和正確的手動所有的.config和的.csproj檔案!
有沒有辦法避免這種噩夢?
額外信息。
該項目和LibB在.Net 4.7上設置。
LibA仍然在.Net 4.5上。
LibA和LibB部署在公司的NuGet存儲庫中。
[更新]
正如意見,我會盡量不要在力霸(和LibB)包Newtonsoft.Json庫建議。其實這是因爲這個(我認爲):
<files>
<file src="bin\$configuration$\**\*.*" exclude="**\*.pdb" target="lib\net40"/>
</files>
我改成了這樣:
<files>
<file src="bin\$configuration$\**\MyCompany.*.*" exclude="**\*.pdb" target="lib\net40"/>
</files>
和它的作品中,Newtonsoft.Json包從拍攝的NuGet。
你能夠使用新的csproj格式嗎?沒有提示路徑,它似乎更好地應付這個... –
它看起來像LibA在其自己的nupkg文件btw中包含Newtonsoft.Json.dll,這可能是導致問題的原因。 –
你可以重寫liba nuget包來引用newtonsoft Json而不是複製DLL嗎? – dariogriffo