错误NU1605检测到包降级

Dav*_*New 22 .net nuget .net-core visual-studio-2017 .net-core-2.0

我在netcoreapp2.0控制台应用程序中遇到以下NU1605依赖项错误:

NU1605  Detected package downgrade: System.Diagnostics.Debug from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version. 
 MyProject -> Colorful.Console 1.2.6 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Diagnostics.Debug (>= 4.3.0) 
 MyProject -> System.Diagnostics.Debug (>= 4.0.11)

NU1605  Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. 
 MyProject -> Colorful.Console 1.2.6 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.Extensions (>= 4.3.0) 
 MyProject -> Colorful.Console 1.2.6 -> System.Runtime.Extensions (>= 4.1.0)    MyProject

NU1605  Detected package downgrade: System.Runtime.Handles from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version. 
 MyProject -> Colorful.Console 1.2.6 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.Handles (>= 4.3.0) 
 MyProject -> Colorful.Console 1.2.6 -> System.IO.FileSystem 4.0.1 -> System.Runtime.Handles (>= 4.0.1)

NU1605  Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. 
 MyProject -> Colorful.Console 1.2.6 -> System.Console 4.0.0 -> runtime.win.System.Console 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0) 
 MyProject -> Colorful.Console 1.2.6 -> System.Runtime.InteropServices (>= 4.1.0)
Run Code Online (Sandbox Code Playgroud)

我已尝试在csproj中引用这些软件包版本,但这并不能解决问题.见csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Colorful.Console" Version="1.2.6" />
    <PackageReference Include="CommandLineParser" Version="2.2.1" />
    <PackageReference Include="DotSpinners" Version="1.2.0" />
    <PackageReference Include="System.Diagnostics.Debug" Version="4.0.11" />
    <PackageReference Include="System.Runtime.Extensions" Version="4.1.0" />
    <PackageReference Include="System.Runtime.Handles" Version="4.0.1" />
    <PackageReference Include="System.Runtime.InteropServices" Version="4.1.0" />
  </ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)

他们似乎恢复正常:

包参考

该项目还引用了Microsoft.NETCore.App 2.0 SDK.

从CLI执行dotnet还原时,我也收到以下错误,我不确定是否相关:

C:\Program Files\dotnet\sdk\2.1.200\NuGet.targets(114,5): error : Failed to retrieve information about 'System.Runtime.Serialization.Formatters' from remote source 'https://mycompany.pkgs.visualstudio.com/_packaging/myid/nuget/v3/flat2/system.runtime.serialization.formatters/index.json'. [C:\MyProject\MyProject.sln]
C:\Program Files\dotnet\sdk\2.1.200\NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\MyProject\MyProject.sln]
Run Code Online (Sandbox Code Playgroud)

我不知道为什么它试图从我们的私人公司包存储库中检索有关'System.Runtime.Serialization.Formatters'的信息.

NuGet.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="mycompany" value="https://mycompany.pkgs.visualstudio.com/_packaging/Stable/nuget/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
     <mycompany>
       <add key="Username" value="vsts" />
       <add key="ClearTextPassword" value="xxx" />
     </mycompany>
   </packageSourceCredentials>
  <disabledPackageSources>
    <add key="Microsoft and .NET" value="true" />
  </disabledPackageSources>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageManagement>
    <add key="format" value="0" />
    <add key="disabled" value="False" />
  </packageManagement>
</configuration>
Run Code Online (Sandbox Code Playgroud)

如果这意味着什么,我还有以下NU1603警告:

NU1603  MyProject depends on System.Runtime.Handles (>= 4.1.0) but System.Runtime.Handles 4.1.0 was not found. An approximate best match of System.Runtime.Handles 4.3.0 was resolved.
Run Code Online (Sandbox Code Playgroud)

Mer*_*lis 72

我在 .netcoreapp2.2 控制台应用程序中遇到了类似的问题。

项目建设成功。但是,发布失败,出现了几个 NU1605 错误。

该问题源于 log4net 2.0.8 版。它在具有以下依赖项的 .netstandard2.0 项目中被引用:

log4net v2.0.8 不包含对 .NetStandard 的特定依赖,Version=2.0

他们导致引用 log4net 的项目中的包降级。在发布期间,这些警告被视为错误......

为了解决这个问题,我通过 Nuget 添加了这些库的正确版本。

log4net 依赖项和其他版本错误的 nuget 包

最后,发布成功。

PS当我第一次添加带有最新版本库的包时,依赖项列表上会显示一个黄色警告标志,好像这些包不适合该项目。卸载项目并重新加载后,警告标志消失了!(我使用的是 Visual Studio 2019)

希望能帮助到你!


Leo*_*SFT 23

错误NU1605检测到包降级

对于错误NU1605:

您可以使用它<NoWarn>NU1605</NoWarn>来清除WarningsAsErrors项目中的内容.

那是因为netcoreapp2.0项目<WarningsAsErrors>NU1605</WarningsAsErrors>默认有.从Properties-> Build-> Treat warning中检查它为错误:

在此输入图像描述

添加如下:

<PackageReference Include="Colorful.Console" Version="1.2.6">
      <NoWarn>NU1605</NoWarn>
</PackageReference>
Run Code Online (Sandbox Code Playgroud)

查看此处的博客文章:MSBuild集成了NuGet警告和错误以及意外的软件包版本警告.

对于错误NU1603:

发生警告是因为Feed中不存在System.Runtime.Handles(> = 4.1.0).通常这是一个包创作错误,因为包依赖于不存在的东西.

您还可以使用<NoWarn>NU1603</NoWarn>解决此问题:

<PropertyGroup>
      <NoWarn>NU1603</NoWarn>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

注意:您会注意到您的项目有另一个警告,请注意DotSpinners参考PackageReference 上的黄色三角形徽章.这是因为该包DotSpinners是一个.NET Framework项目,与您的.NET Core项目不兼容.

希望这可以帮助.

  • 很好的信息,但实际上并没有解决问题,它只是在构建过程中忽略了问题。发布时,当这些 dll 尝试加载时,您将收到运行时错误。请参阅梅尔特的回答。 (10认同)
  • 我真的非常不喜欢这个答案。消除警告永远不应该成为解决方案。尤其是当有替代方案时。 (2认同)

ari*_*had 10

刚刚与.Net core 3.1和有同样的问题(NU1605)log4Net

错误 NU1605:检测到包降级:System.Net.NameResolution 从 4.3.0 到 4.0.0。

我所做的是添加 Nuget 引用System.Net.NameResolution并安装 4.3.0 版,然后关闭 Visual Studio 并重新打开解决方案。

  • 对我来说,只需重新启动 Visual Studio 即可。奇怪的。 (2认同)

Fra*_*ein 6

以上所有对我的 .NET Core 3.1 项目都没有帮助。

完全重新编译后,错误NU1605一次又一次地出现。csproj 文件中对版本号的所有引用都是正确的。

最终有帮助的是删除 obj 文件夹

之后重新编译工作没有问题。


Tvd*_*vdH 6

我在尝试更新 Nuget 包时遇到了 .NET 5 的 NU1605。

本文中示例 2 的解决方案非常适合我。

简而言之,我只需添加

<PackageReference Include="Microsoft.NETCore.Targets" Version="5.0.0" PrivateAssets="all" />
Run Code Online (Sandbox Code Playgroud)

到项目的 ItemGroup,这是更新的目标(在 VS 中,当我双击“检测到包降级”错误消息时,会出现相关的 .csproj)。


小智 5

确保您使用相同的版本进行构建和发布,您可以修复它,在 PropertyGroup 下的 .csproj 文件中添加 2.1.9 这应该与您当前的设置版本匹配。前任:

  <PropertyGroup>
      <OutputType>Exe</OutputType>
      <TargetFramework>netcoreapp2.1</TargetFramework>    
      <RuntimeFrameworkVersion>2.1.9</RuntimeFrameworkVersion> 
  </PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:NETSDK1061:该项目是使用 Microsoft.NETCore.App 版本 2.1.9 恢复的,但在当前设置下,将使用版本 2.1.0。


Stu*_*art 5

我遇到的导致此错误的原因是在一个或多个 .csproj 文件中多次引用同一个包。在我们的例子中,这些引用是对我们自己的 nuget 存储库中的本地依赖项。

这对 Visual Studio 中的开发人员是不可见的,因此您需要在单独的编辑器中打开 .csproj 文件。

对于我的团队,我认为原因是依赖库和消耗该依赖项的解决方案中的大量流失的组合。无论出于何种原因, git merge 都会在 .csproj 文件中采用两个版本,而不会引发冲突。在几个项目文件中,我发现了相同依赖项的 3 个版本。