Dot-Net
錯誤 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 中引用這些包版本,但這並不能解決問題。參見 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>他們似乎恢復得很好:
該項目還引用了Microsoft.NETCore.App 2.0 SDK。
從 CLI 執行 dotnet restore 時,我還收到以下錯誤,我不確定是否相關:
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.
我對 .netcoreapp2.2 控制台應用程序有類似的問題。
該項目建設成功。但是,發布失敗並出現多個 NU1605 錯誤。
問題源於 log4net 版本 2.0.8。它在具有以下依賴項的 .netstandard2.0 項目中被引用:
他們在引用 log4net 的項目中導致包降級。在發布期間,這些警告被視為錯誤……
為了解決這個問題,我通過 Nuget 添加了這些庫的正確版本。
最後,發布成功。
PS當我第一次使用最新版本的庫添加包時,依賴列表上會顯示一個黃色警告標誌,就好像這些包不適合該項目一樣。解除安裝項目並重新載入後,警告標誌消失了!(我正在使用 Visual Studio 2019)


