错误 NU1605检测到软件包降级

在我的 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)

我已经尝试在 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>

它们似乎确实恢复了良好状态:

Package References

该项目还引用了 NETCore 应用程序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]

我不知道它为什么要检索“系统”的信息。运行时间。序列化。来自我们的私有公司软件包存储库的。

配置:

<?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>

我也有以下 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.
118036 次浏览

Error NU1605 Detected package downgrade

For the error NU1605:

You can use <NoWarn>NU1605</NoWarn> to clear the WarningsAsErrors in your project.

That because netcoreapp2.0 projects have <WarningsAsErrors>NU1605</WarningsAsErrors> by default. Check it from Properties->Build->Treat warning as errors:

enter image description here

Add like following:

<PackageReference Include="Colorful.Console" Version="1.2.6">
<NoWarn>NU1605</NoWarn>
</PackageReference>

Check the blog post here: MSBuild integration of NuGet warnings and errors and Unexpected package version warnings.

For the error NU1603:

The warning occurs because System.Runtime.Handles (>= 4.1.0) does not exist in the feed. Typically this is a package authoring error because the package depends on something that doesn't exist.

You can also use <NoWarn>NU1603</NoWarn> to resolve this issue:

<PropertyGroup>
<NoWarn>NU1603</NoWarn>
</PropertyGroup>

Note:You would notice that your project has another warning, notice the yellow triangle insignia on the PackageReference DotSpinners on Reference. That because the package DotSpinners is a .NET Framework project, not compatible with your .NET Core project.

Make sure that you are using same version for build and publish you can fix it adding 2.1.9 in .csproj file under PropertyGroup this should match with your current settings version. Ex:

  <PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.9</RuntimeFrameworkVersion>
</PropertyGroup>

Error which I got was: NETSDK1061: The project was restored using Microsoft.NETCore.App version 2.1.9, but with current settings, version 2.1.0 would be used instead.

Something that I've run into that causes this error is having multiple references to the same package in one or more .csproj files. In our case, these references are to local dependencies in our own nuget repository.

This is invisible to a developer in Visual Studio, so you need to open the .csproj file in a separate editor.

For my team, I think the cause is a combo of a lot of churn in both a dependent library and the solution that consumes that dependency. For whatever reason, a git merge will take both versions in the .csproj file without raising a conflict. In several project files, I found 3 versions of the same dependency.

I had a similar issue with a .netcoreapp2.2 console application.

The project was building successfully. However, publishing was failing with several NU1605 errors.

The problem was originated from log4net version 2.0.8. It was referenced in a .netstandard2.0 project with the following dependencies:

log4net v2.0.8 does not include specific dependency for .NetStandard,Version=2.0

They were causing package downgrades in the projects referencing log4net. And during publish these warnings are treated as errors...

To solve the problem I added correct versions of these libraries via Nuget.

log4net dependencies and additional nuget packages for version errors

Finally, the publishing succeeded.

P.S. When I first added packages with the newest version of libraries, a yellow warning sign was displayed on the dependencies list as if the packages were not suitable for that project. After unloading the project and loading back the warning sign gone! (I'm using Visual Studio 2019)

I had this problem with a .Net Core 2.2 project using a .Net Standard 2.0 DLL in the same solution. I had the errors reported for the .Net Standard DLL when I added several SeriLog packages to the .Net Core application. I backed out the changes, then added the SeriLog packages one-by-one, cleaning and rebuilding between each addition. This time there was no error...

I faced a similar problem (NU1605) when publishing but I figured out was the runtime linux-x64. So I removed the runtime option and the problem has gone.

I am not sure if this is the best option or the way to fix this problem, but i had the same issue:

NuGet Warning NU1605 (package downgrade)

My process of elimination was to make sure my project was: 1. Saved 2. Build Solution (ctrl shift b) (only error was the NU1605) 3. Right click project folder, click into Manage NuGet packages. 4. Click on Updates, I personally updated all packages. 5. (Step 2 again).

This was all i needed to do. Hopefully this was the same outcome.

Just had the same issue (NU1605) with .Net core 3.1 and log4Net:

error NU1605: Detected package downgrade: System.Net.NameResolution from 4.3.0 to 4.0.0.

What I did is adding a Nuget reference to System.Net.NameResolution and install version 4.3.0, then I closed Visual Studio and re-opened the Solution.

All of the above did not help me with my .NET Core 3.1 project.

The error NU1605 reappeared again and again after complete recompilation. All references to the version number have been correct in the csproj file.

What finally helped was to delete the obj folder!

Afterwards the recompilation worked without problems.

I had a similar issue, where my project had package reference like this:

Package references:

  • Package A
  • Package B
    • Package A

So because project B reference package A, I just deleted package A from the main packages list and was left with Package B referencing Package A. I rebuilt the solution and the problem was gone.

There are already a bunch of answers to the question, many of them fixing the problem, but I think the solution I applied is cleaner than everything else I saw online.

As stated, the usual suspect of the error in .Net Core 3.1 is some assembly depending upon a library requiring a System.* or Microsoft.* assembly.

When the build runs, everything can be fine, because the resolution of assemblies is using only project references.
When a "Publish" build is performed, with a runtime selected, the resolution of assemblies doesn't follow the algorithm used by Nuget when restoring, so the Warning creeps up.

From this situation, follows my solution: when we perform a build with a target runtime, we want to enforce that the correct runtime version is selected.

In the .csproj file, I added this:

<!-- adjust runtime and package version accordingly -->
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'win-x64' ">
<PackageReference Include="Microsoft.NETCore.Targets" Version="3.1.0" />
</ItemGroup>

The Microsoft.NETCore.Targets package, found at this link (which has lots of info on the warning) is one of the solutions to the dreaded warning, and having it included only in the publish build keeps all the other builds untouched. The nice thing of this package is that it is one package, and includes all the runtime.

I had this problem when adding a Connected Service reference to an ASP.Net Webservice. Added this reference in project Nop.Plugin.SDE causing a reference to System.ServiceModel.Http 4.4.4 to be added, while it already was referencing project Nop.Services having a reference to System.ServiceModel.Http 4.7.0. The solution was to upgrade the reference to System.ServiceModel.Http to version 4.7.0 from project Nop.Plugin.SDE.

Solution explorer after adding reference

Upgrade System.ServiceModel.Http from 4.4.4 to 4.7.0

Reference to System.ServiceMode.Http from Nop.Services

The GraphQL nuGet package I was referencing had a dependency to Newtonsoft.Json(>= 10.0.3). The only solution was the following:

  • Remove the GraphQL nuGet package.
  • Install the latest NewtonSoft.Json package v12.0.3
  • Go back and reinstall the GraphQL nuGet package.

Somewhy dotnet restore brings dependency warnings only on RuntimeIdentifier:win10-x64. portable runtime works normally.

After going through all the advices above, and taking reference from the accepted answer from @Mert, what worked for me was deleting the specific package that was causing the inconsistency.

enter image description here

Inside package folder, visual studio very helpfully marks the package causing the issue with a yellow warning sign.

I deleted the package and used NuGet to install the appropriate version of the package.

I ran into NU1605 with .NET 5 while trying to update a Nuget package.

The solution to Example 2 in this article worked perfectly for me.

In short, I only had to add

<PackageReference Include="Microsoft.NETCore.Targets" Version="5.0.0" PrivateAssets="all" />

to the ItemGroup of the project, which was the target of the update (in VS, the relevant .csproj appeared when I doubleclicked on the "Detected package downgrade" error message).

may be some one added a new project with new version and there may be some project with old version. upgrading all the projects to the same version would fix the issue.

This post helped me to solve the same problem temporary which happened to me recently. Later, I learnt it is something related to how NuGet resolves package dependencies.

According to Microsoft documentation "When the package graph for an application contains different versions of the same package, NuGet chooses the package that's closest to the application in the graph and ignores all others. This behavior allows an application to override any particular package version in the dependency graph." that is why it results in a downgrade of the package version. So, this rule is applied with a warning to alert the user.  the application depends directly on Package B with a version constraint of >=2.0. The application also depends on Package A which in turn also depends on Package B, but with a >=1.0 constraint. Because the dependency on Package B 2.0 is nearer to the application in the graph, that version is used:

This is a screenshot of the NugetPacKage manager of my code. As it is shown in the picture, the version of Serilog.Sink.Console of the Library and the Trading project are different. enter image description here I just uninstalled older one and installed new one. possibly, uninstallation of newer one will also work.

Actually, the solutions which were proposed in this page worked for me. I just wanted to share something that I found interesting, as an enthusiastic programmer. hope it will help.