检测到包降级警告(dotnet core,vs 2017)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42709533/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 09:53:13  来源:igfitidea点击:

Detected package downgrade warning (dotnet core, vs 2017)

.netnuget.net-corevisual-studio-2017csproj

提问by Nik

I have just updated all my nuget packages for my solution (dotnet core 1.1 project).

我刚刚为我的解决方案(dotnet core 1.1 项目)更新了所有 nuget 包。

I am now getting the following warnings and I don't really know what they mean.

我现在收到以下警告,我真的不知道它们是什么意思。

NETStandard.Library downgrade warning

NETStandard.Library 降级警告



Update:I am still getting warnings mentioned above. My web projects warn about the Microsoft.NETCore.App package (see screenshot below) and my lib projects warn about NETStandard.Library (see screenshot above)

更新:我仍然收到上面提到的警告。我的 web 项目警告 Microsoft.NETCore.App 包(见下面的截图)和我的 lib 项目警告 NETStandard.Library(见上面的截图)

Microsoft.NETCore.App downgrade warning

Microsoft.NETCore.App 降级警告

When trying to update Microsoft.NETCore.App in the NuGet package manager, I am getting the following error:

尝试在 NuGet 包管理器中更新 Microsoft.NETCore.App 时,出现以下错误:

NuGet upgrade error

NuGet 升级错误

Hope someone can help me get rid of those warnings and setup everything it is meant to be, so I can update all my packages.

希望有人可以帮助我摆脱这些警告并设置它应该做的一切,这样我就可以更新我的所有软件包。

Thanks in advance!

提前致谢!

采纳答案by Nik

As per answer above the working solution is to remove the following line from your csproj file.

根据上面的答案,工作解决方案是从您的 csproj 文件中删除以下行。

Web App project:

网络应用项目:

<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>

Lib project:

库项目:

<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>

回答by Jimmy Shaw

This situation occurred to me after opening an existing solution but instead of Warnings, they were Errors.

在打开现有解决方案后,我遇到了这种情况,但不是警告,而是错误。

I opened the YourAwesomeApp.csproj file and went through the "Detected package downgrade" errors one-by-one and manually changed the version of that line item from the existing version to the specified version that was shown in the error itself.

我打开了 YourAwesomeApp.csproj 文件并逐一检查了“检测到的包降级”错误,并手动将该行项目的版本从现有版本更改为错误本身中显示的指定版本。

For example, if the Error says downgrade detected "SqlServer 1.0.4 -> 1.0.3" then find the line for package SqlServer and edit the version from 1.0.3 to 1.0.4.

例如,如果错误显示降级检测到“SqlServer 1.0.4 -> 1.0.3”,则找到包 SqlServer 的行并将版本从 1.0.3 编辑为 1.0.4。

Those errors should disappear after building the project.

构建项目后,这些错误应该会消失。

The downside to this that I only had 5 errors this time but what if another person's project contained say 50 such errors. Then that person's task of manually editing those lines would be very tedious and time-consuming.

这样做的缺点是这次我只有 5 个错误,但是如果另一个人的项目包含 50 个这样的错误怎么办。那么那个人手动编辑这些行的任务将是非常乏味和耗时的。

回答by Stephen Elmendorf

This generally happens because the item you are attempting to install requires a more recent version of a sub-dependency than you have already included in your project.

这通常是因为您尝试安装的项目需要比您已包含在项目中的子依赖项的更新版本。

The solution is to update or delete the existing dependency that is in your project prior to installing the package.

解决方案是在安装包之前更新或删除项目中的现有依赖项。

Example:

例子:

Detected package downgrade: Newtonsoft.Json from 9.0.0 to 8.0.0.

检测到包降级:Newtonsoft.Json 从 9.0.0 到 8.0.0。

This meansyou have Newtonsoft.Json 8.0.0 already listed as a dependency in your project, but the package you are trying to install requires at least version 9.0.0 as a dependency.

这意味着您的项目中已将 Newtonsoft.Json 8.0.0 列为依赖项,但您尝试安装的包至少需要 9.0.0 版作为依赖项。

This is becauseVisual studio won't automatically upgrade this dependency as you've specified an explicit version for your project. You can either upgrade the dependency in your project to the minimum required version or remove it from your project, and let the package you're installing handle it.

这是因为Visual Studio 不会自动升级此依赖项,因为您已为项目指定了显式版本。您可以将项目中的依赖项升级到所需的最低版本,也可以将其从项目中删除,然后让正在安装的包处理它。

To resolve this, in our example above, this would mean finding 'Newtonsoft.Json 8.0.0' and upgrading it to version '9.0.0' or simply removing it from your project prior to installing your package.

要解决这个问题,在我们上面的示例中,这意味着找到“Newtonsoft.Json 8.0.0”并将其升级到“9.0.0”版本,或者在安装包之前将其从项目中删除。

回答by Gerard Wilkinson

In my case neither of those properties were set in my csproj files.

在我的情况下,这些属性都没有在我的 csproj 文件中设置。

I had to tell VS to update those packages via NuGet.

我不得不告诉 VS 通过 NuGet 更新这些包。

The warnings appeared for me after resolving the warning for explicit reference to implicit dependency .NETCore.App after moving from 1.0 to 1.1.

在解决了从 1.0 到 1.1 后显式引用隐式依赖项 .NETCore.App 的警告后,我出现了警告。

UPDATE 21/09/17

更新 21/09/17

This also seems to affect upgrades to 2.0, the resolution is the same. Update those packages manually with NuGet. Thanks to IbrarMumtaz for pointing this out!

这似乎也影响升级到2.0,分辨率是一样的。使用 NuGet 手动更新这些包。感谢 IbrarMumtaz 指出这一点!

回答by mrapi

I was able to fix some error like that adding NoWarn in cproj

我能够修复一些错误,比如在 cproj 中添加 NoWarn

<Project Sdk="Microsoft.NET.Sdk">

 <PropertyGroup>
    <NoWarn>$(NoWarn);NU1605</NoWarn>
  </PropertyGroup>

...
</Project>

You may want to add it only temporarily during multiple package upgrade and remove it later.

您可能只想在多个软件包升级期间临时添加它并稍后将其删除。

回答by Drew Noakes

I was able to get rid of these warnings in my project by removing the <NetStandardImplicitPackageVersion>element from the csprojfile.

通过<NetStandardImplicitPackageVersion>csproj文件中删除元素,我能够在我的项目中摆脱这些警告。

There's some information in this articleabout implicit metapackages, which seems to be the root cause of this problem.

这篇文章中有一些关于隐式元包的信息,这似乎是这个问题的根本原因。

You might also need to update some dependencies. For example, I had to upgrade BenchmarkDotNetfrom 0.10.1to 0.10.3to get rid of a few warnings like the ones you're seeing.

您可能还需要更新一些依赖项。例如,我不得不升级BenchmarkDotNet0.10.10.10.3摆脱像那些你看到几个警告。

回答by Robert Brooker

Try using NuGet

尝试使用 NuGet

I was getting:

我得到:

error NU1605: Detected package downgrade: System.Net.NameResolution from 4.3.0 to 4.0.0. Reference the packagedirectly from the project to select a different version.

错误 NU1605:检测到包降级:System.Net.NameResolution 从 4.3.0 到 4.0.0。直接从项目中引用包以选择不同的版本。

So I referenced the package directory by running (in the project folder):

所以我通过运行(在项目文件夹中)引用了包目录:

dotnet add package System.Net.NameResolution

See NuGet Errors - NU1605

请参阅NuGet 错误 - NU1605

Issue:

问题:

A dependency package specified a version constraint on a higher version of a package than restore ultimately resolved. That is, because of the "nearest wins" rule when resolving packages, a nearer package in the graph may have overridden a distant package.

一个依赖包指定了一个比最终解决的还原更高版本的包的版本约束。也就是说,由于解析包时的“最近获胜”规则,图中较近的包可能已覆盖较远的包。

Solution:

解决方案:

Add a direct reference to the project for the higher version of the package that you want to use.

为要使用的更高版本的包添加对项目的直接引用。

回答by Emil

Try removing:

尝试删除

<IsPackable>false</IsPackable>

from your project file - this is what worked for me!

来自您的项目文件 - 这对我有用!

If you are still left with NU1605Error code you can ignore it by adding the following to your project file:

如果您仍然留下NU1605错误代码,您可以通过将以下内容添加到您的项目文件中来忽略它:

<PropertyGroup>
    <NoWarn>NU1605</NoWarn>
</PropertyGroup>

回答by Max Favilli

Manually removing the nuget packages dependencies from the project and Install-Package for each of them fixed the problem in my case.

从项目中手动删除 nuget 包依赖项,并为每个包安装包解决了我的问题。

回答by knocte

In my case, this error was not related to .NET Core but to .NET Standard.

就我而言,此错误与 .NET Core 无关,而是与 .NET Standard 相关。

I had two libraries A, and B. Library A depended on some nuget package X, and library B depended on A. Once I upgraded X to a new version, somehow it started depending on a new version of NETStandard.Library nuget package(from 2.0.2 to 2.0.3), which broke the build of B with the error Detected package downgrade: NETStandard.Library from 2.0.3 to 2.0.2. Reference the package directly from the project to select a different version.

我有两个库 A 和 B。库 A 依赖于某个 nuget 包 X,库 B 依赖于 A。一旦我将 X 升级到新版本,它就以某种方式开始依赖于新版本的NETStandard.Library nuget 包(来自2.0.2 到 2.0.3),这破坏了 B 的构建并出现错误Detected package downgrade: NETStandard.Library from 2.0.3 to 2.0.2. Reference the package directly from the project to select a different version

Once I added the NETStandard.Library nuget packageas a dependency to B (obviously targetting the latest version 2.0.3), the error went away, even if a new warning appeared:

一旦我将 NETStandard.Library nuget 包作为依赖项添加到 B(显然针对最新版本 2.0.3),即使出现新警告,错误也消失了:

/usr/local/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets(5,5): Warning NETSDK1023: A PackageReference for 'NETStandard.Library' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs(NETSDK1023) (GWallet.Frontend.XF)

/usr/local/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets(5,5): 警告 NETSDK1023: A PackageReference for 'NETStandard.Library ' 已包含在您的项目中。此包由 .NET SDK 隐式引用,您通常不需要从项目中引用它。有关更多信息,请参阅https://aka.ms/sdkimplicitrefs(NETSDK1023) (GWallet.Frontend.XF)