.net 错误 NU1605 检测到包降级
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50286990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error NU1605 Detected package downgrade
提问by Dave New
I am experiencing the following NU1605 dependency errors in my netcoreapp2.0console application:
我在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)
I have tried referencing these package versions in csproj, but this doesn't fix the problem. See csproj:
我曾尝试在 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>
And they do seem to restore fine:
他们似乎恢复得很好:
The project is also referencing the Microsoft.NETCore.App 2.0SDK.
该项目还引用了Microsoft.NETCore.App 2.0SDK。
When performing dotnet restore from the CLI, I also get the following error, which I am not sure is related:
从 CLI 执行 dotnet restore 时,我还收到以下错误,我不确定是否相关:
C:\Program Files\dotnet\sdk.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.1.200\NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\MyProject\MyProject.sln]
I have no idea why it's trying to retrieve information about 'System.Runtime.Serialization.Formatters' from our private company package repository.
我不知道为什么它试图从我们的私人公司包存储库中检索有关“System.Runtime.Serialization.Formatters”的信息。
NuGet.config:
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>
I also have the following NU1603 warning if this means anything:
如果这意味着什么,我也有以下 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.
回答by Leo Liu-MSFT
Error NU1605 Detected package downgrade
错误 NU1605 检测到包降级
For the error NU1605:
对于错误NU1605:
You can use <NoWarn>NU1605</NoWarn>to clear the WarningsAsErrorsin your project.
您可以使用<NoWarn>NU1605</NoWarn>清除WarningsAsErrors项目中的 。
That because netcoreapp2.0projects have <WarningsAsErrors>NU1605</WarningsAsErrors>by default. Check it from Properties->Build->Treat warning as errors:
那是因为netcoreapp2.0项目<WarningsAsErrors>NU1605</WarningsAsErrors>默认有。从 Properties->Build->Treat warning as errors 检查它:
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 errorsand Unexpected package version warnings.
在此处查看博客文章:NuGet 警告和错误的 MSBuild 集成以及意外的包版本警告。
For the error NU1603:
对于错误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.
出现警告是因为System.Runtime.Handles(>= 4.1.0) 在提要中不存在。通常这是一个包创作错误,因为包依赖于不存在的东西。
You can also use <NoWarn>NU1603</NoWarn>to resolve this issue:
您还可以使用<NoWarn>NU1603</NoWarn>来解决此问题:
<PropertyGroup>
<NoWarn>NU1603</NoWarn>
</PropertyGroup>
Note:You would notice that your project has another warning, notice the yellow triangle insignia on the PackageReference DotSpinnerson Reference. That because the package DotSpinnersis a .NET Framework project, not compatible with your .NET Core project.
注意:您会注意到您的项目有另一个警告,请注意DotSpinnersReference上 PackageReference上的黄色三角形标志。那是因为该包DotSpinners是一个 .NET Framework 项目,与您的 .NET Core 项目不兼容。
Hope this helps.
希望这可以帮助。
回答by Mert Can Ilis
I had a similar issue with a .netcoreapp2.2 console application.
我在 .netcoreapp2.2 控制台应用程序中遇到了类似的问题。
The project was building successfully. However, publishing was failing with several NU1605 errors.
项目建设成功。但是,发布失败,出现了几个 NU1605 错误。
The problem was originated from log4net version 2.0.8. It was referenced in a .netstandard2.0 project with the following dependencies:
该问题源于 log4net 2.0.8 版。它在具有以下依赖项的 .netstandard2.0 项目中被引用:
They were causing package downgrades in the projects referencing log4net. And during publish these warnings are treated as errors...
他们导致引用 log4net 的项目中的包降级。在发布期间,这些警告被视为错误......
To solve the problem I added correct versions of these libraries via Nuget.
为了解决这个问题,我通过 Nuget 添加了这些库的正确版本。
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)
PS当我第一次添加带有最新版本库的包时,依赖项列表上会显示一个黄色警告标志,好像这些包不适合该项目。卸载项目并重新加载后,警告标志消失了!(我使用的是 Visual Studio 2019)
Hope it helps!
希望能帮助到你!
回答by PRathore
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 下的 .csproj 文件中添加 2.1.9 这应该与您当前的设置版本匹配。前任:
<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.
我得到的错误是:NETSDK1061:该项目是使用 Microsoft.NETCore.App 版本 2.1.9 恢复的,但在当前设置下,将使用版本 2.1.0。
回答by Stuart
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.
我遇到的导致此错误的原因是在一个或多个 .csproj 文件中多次引用同一个包。在我们的例子中,这些引用是对我们自己的 nuget 存储库中的本地依赖项。
This is invisible to a developer in Visual Studio, so you need to open the .csproj file in a separate editor.
这对 Visual Studio 中的开发人员是不可见的,因此您需要在单独的编辑器中打开 .csproj 文件。
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.
对于我的团队,我认为原因是依赖库和消耗该依赖项的解决方案中的大量流失的组合。无论出于何种原因, git merge 都会在 .csproj 文件中采用两个版本,而不会引发冲突。在几个项目文件中,我发现了相同依赖项的 3 个版本。
回答by arielhad
Just had the same issue (NU1605) with .Net core 3.1and log4Net:
刚刚与.Net core 3.1和有同样的问题(NU1605)log4Net:
error NU1605: Detected package downgrade: System.Net.NameResolution from 4.3.0 to 4.0.0.
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.NameResolutionand install version 4.3.0, then I closed Visual Studio and re-opened the Solution.
我所做的是添加 Nuget 引用System.Net.NameResolution并安装 4.3.0 版,然后关闭 Visual Studio 并重新打开解决方案。
回答by Jones
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)
NuGet 警告 NU1605(包降级)
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).
我的消除过程是确保我的项目是: 1. 保存 2. 构建解决方案(ctrl shift b)(唯一的错误是 NU1605) 3. 右键单击项目文件夹,单击进入管理 NuGet 包。4.点击Updates,我亲自更新了所有的包。5.(再次执行第 2 步)。
This was all i needed to do. Hopefully this was the same outcome.
这就是我需要做的所有事情。希望这是同样的结果。
回答by Mark
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...
我在同一解决方案中使用 .Net Standard 2.0 DLL 的 .Net Core 2.2 项目遇到了这个问题。当我将几个 SeriLog 包添加到 .Net Core 应用程序时,我报告了 .Net Standard DLL 的错误。我取消了更改,然后一个一个地添加 SeriLog 包,在每次添加之间进行清理和重建。这次没有报错...
回答by Gandarez
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.
我在发布时遇到了类似的问题(NU1605),但我发现是运行时linux-x64。所以我删除了运行时选项,问题就解决了。


