简体   繁体   English

.Net NuGet软件包冲突-DLL Hell又回来了

[英].Net NuGet package conflicts - DLL Hell is back

I have a Visual Studio project. 我有一个Visual Studio项目。
It requires the Newtonsoft.Json library. 它需要Newtonsoft.Json库。
It is referenced with the NuGet package manager of Visual Studio 2017. Actually the version 10.0.3. Visual Studio 2017的NuGet包管理器引用了它。实际上是版本10.0.3。

This project is referencing the NuGet package LibA and LibB. 该项目引用了NuGet包LibA和LibB。

LibA uses Newtonsoft.Json version 8 and this is defined in the package.nuspec: 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 uses NewtonSoft.Json version 10 and this is defined in the package.nuspec: LibB使用NewtonSoft.Json版本10,这在package.nuspec中定义:

<dependency id="RestSharp" version="105.1" />
<dependency id="Newtonsoft.Json" version="10.0.3" />

When I update the LibA package (for example from version 1.1 to 1.2) using the NuGet Package Manager of Visual Studio 2017 (on the solution) it updates the reference of the LibA package as expected in the .csproj file: 当我使用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>

but it also update the reference of the Newtonsoft.Json library: 但它也会更新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>

and the app/web.config file: 和app / 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" />

It also update correctly the LibA reference in the package.config: 它还可以正确更新package.config中的LibA参考:

 -  <package id="LibA.MyService" version="1.1" targetFramework="net45" />
 +  <package id="LibA.MyService" version="1.2" targetFramework="net45" />

but it leaves the WRONG reference to the Newtonsoft.Json library version: 但是它留下了对Newtonsoft.Json库版本的错误引用:

<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net47" />

I complain about 2 things: 我抱怨两件事:

  1. If I open the NuGet Package Manager it is showing that I'm using the Newtonsoft.Json version 10.0.3 in the current project: 如果我打开NuGet软件包管理器,则表明我在当前项目中使用的是Newtonsoft.Json版本10.0.3:
    this is not true because when I build the solution in the bin folder it is stored version 8.0.3 and it is not possible to update the Newtonsoft.Json because it is "already" updated. 这是不正确的,因为当我在bin文件夹中构建解决方案时,它存储的版本是8.0.3,并且无法更新Newtonsoft.Json,因为它已经“已”更新。
    Furthermore my project and the LibB that needs the vesion 10 are actually using version 8. 此外,我的项目和需要vesion 10的LibB实际上正在使用版本8。

  2. I cannot decide to maintain the version 10 automatically, actually I have to merge and correct manually all the .config and .csproj files ! 我无法决定自动维护版本10, 实际上我必须手动合并和更正所有.config和.csproj文件

There is a way to avoid this nightmare? 有办法避免这种噩梦吗?

Extra info. 额外信息。
The project and the LibB are set on .Net 4.7. 该项目和LibB在.Net 4.7上设置。
LibA is still on .Net 4.5. LibA仍在.Net 4.5上。
LibA and LibB are deployed in the company NuGet repository. LibA和LibB部署在公司NuGet存储库中。

[Update] [更新]
As suggested in the comments I'll try to NOT include the Newtonsoft.Json library in the LibA (and LibB) packages. 正如评论中所建议的那样,我将尽量不在LibA(和LibB)软件包中包含Newtonsoft.Json库。 Actually it happens because of this (I think): 实际上是因为这个原因(我认为):

  <files>
    <file src="bin\$configuration$\**\*.*" exclude="**\*.pdb" target="lib\net40"/>     
  </files>

I changed it to this: 我将其更改为:

<files>
    <file src="bin\$configuration$\**\MyCompany.*.*" exclude="**\*.pdb" target="lib\net40"/>     
</files>

and it works, the Newtonsoft.Json package is taken from NuGet. 它的工作原理是,Newtonsoft.Json软件包取自NuGet。

Your first complaint is not correct. 您的第一个投诉不正确。 The NuGet Package Manager shows you what version of the NuGet package , not the version number embedded in the DLL. NuGet程序包管理器向您显示NuGet程序包的版本,而不是DLL中嵌入的版本号。 You could argue that the Package Manager should detect this, but it's really an edge case caused by a bad LibA package. 您可能会争辩说包管理器应该检测到此情况,但这实际上是由不良LibA包引起的边缘情况。

You are correct about the fix: <file src="bin\\$configuration$\\**\\*.*" exclude="**\\*.pdb" target="lib\\net40"/> should not be used. 您对该修复程序是正确的:不应使用<file src="bin\\$configuration$\\**\\*.*" exclude="**\\*.pdb" target="lib\\net40"/>
Ideally, you only include the assemblies produced by building the project. 理想情况下,您只包括构建项目所产生的装配。 If you include dependencies, both internal (eg MyCompany.Common.dll ) or external (eg OtherCompany.dll ), you risk running into this problem. 如果包括内部(例如MyCompany.Common.dll )或外部(例如OtherCompany.dll )依赖项,则可能会OtherCompany.dll此问题。 Put the dependencies on an internal NuGet server. 将依赖项放在内部NuGet服务器上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET Nuget程序包冲突 - .NET Nuget package conflicts 如何解决.NET Dll地狱? - How to resolve .NET Dll Hell? 使用nuget时,如何解决dll的问题? - When using nuget, how can i solve dll hell? Nuget DLL地狱:无法加载文件或程序集System.Runtime - Nuget DLL Hell: Could not load file or assembly System.Runtime In .NET Core, ASP.NET Core - What is the relationship between Package, Reference, NuGet Package, DLL file, Namespace - In .NET Core, ASP.NET Core - What is the relationship between Package, Reference, NuGet Package, DLL file, Namespace 添加对dll的引用与在.NET Standard项目中添加NuGet包 - Add Reference to dll vs. adding a NuGet package in .NET Standard project .Net Core Nuget包版本不匹配:两个包引用了同一个dll的不同版本 - .Net Core Nuget Package Version mismatch: Two packages have references to different versions of the same dll Newtonsoft Json.NET版本不兼容(DLL地狱) - Newtonsoft Json.NET version incompatibility (DLL hell) 无法引用 Nuget 包中包含的 dll - Unable to reference dll included in a Nuget Package 哪个nuget软件包在Nuget中包含Microsoft.WindowsAzure.StorageClient.dll - Which nuget package holds the Microsoft.WindowsAzure.StorageClient.dll in Nuget
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM