错误NU1605检测到包降级

问题描述 投票:12回答:3

我在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中引用这些软件包版本,但这并不能解决问题。见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

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

我不知道为什么它试图从我们的私人公司包存储库中检索有关'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>

如果这意味着什么,我还有以下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.
.net visual-studio-2017 .net-core nuget .net-core-2.0
3个回答
14
投票

错误NU1605检测到包降级

对于错误NU1605:

您可以使用<NoWarn>NU1605</NoWarn>清除项目中的WarningsAsErrors

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

enter image description here

添加如下:

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

查看这里的博客文章:MSBuild integration of NuGet warnings and errorsUnexpected package version warnings

对于错误NU1603:

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

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

<PackageReference>
      <NoWarn>NU1603</NoWarn>
</PackageReference>

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

希望这可以帮助。


2
投票

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

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

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


0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.