.NET NuGet 包验证不显示有关重大更改的任何输出

.NET NuGet Package Validation does not show any output on breaking changes

我有一个创建 nuget 包的 .NET 项目,我想按照此处所述添加 PackageValidation: https://docs.microsoft.com/en-us/dotnet/fundamentals/package-validation/overview

我的 sdk 样式项目文件中有这些行:

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>symbols.nupkg</SymbolPackageFormat>
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>8.0.1</PackageValidationBaselineVersion>

但是我没有得到任何输出,即使我对程序集添加了重大更改。

只有当我将 BaseLineVersion 更改为不存在的数字时,我才会看到一些相关输出:

SsiProxyNuGet.csproj : error NU1102: Unable to find package SsiProxy with version (= 8.0.0)
SsiProxyNuGet.csproj : error NU1102:   - Found 4 version(s) in ASM-NuGet [ Nearest version: 8.0.1 ]
SsiProxyNuGet.csproj : error NU1102:   - Found 0 version(s) in Microsoft Visual Studio Offline Packages
SsiProxyNuGet.csproj : error NU1102:   - Found 0 version(s) in nuget.org

有人有 .net 包验证工作吗?

更新: 我创建了一个新的 .NET 6 项目来测试,发布了一个版本为 1.0.0 的包,将我的版本增加到 1.0.1 并对库进行了重大更改。然后我在构建时收到此消息:

error CP0002: Member 'PackageValidationTest.Calc.Sum(int, int)' exists on [Baseline] lib/net6.0/PackageValidationTest.dll but not on lib/net6.0/PackageValidationTest.dll

为什么这不适用于我现有的项目???

更新2: 对 .Net6、.net standard 2.0 和 .net 4.8 中的新项目进行了更多测试和验证。

对于我的新 .net 4.8 项目,我在添加重大更改后在输出中看到了这一点:

Target RunPackageValidation: Using "Microsoft.DotNet.Compatibility.ValidatePackage" task from assembly "C:\Program Files\dotnet\sdk.0.201\Sdks\Microsoft.NET.Sdk\targets..\tools\net472\Microsoft.DotNet.Compatibility.dll". Task "Microsoft.DotNet.Compatibility.ValidatePackage" Breaking changes to the API surface between 'lib/net48/PackageValidationTestNetFramework.dll' (left) and 'lib/net48/PackageValidationTestNetFramework.dll' (right) for versions 1.0.0 and 1.0.1 respectively: C:\Program Files\dotnet\sdk.0.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Compatibility.Common.targets(32,5): error CP0002: Member 'PackageValidationTestNetFramework.Calc.Sum(int, int)' exists on [Baseline] lib/net48/PackageValidationTestNetFramework.dll but not on lib/net48/PackageValidationTestNetFramework.dll Done executing task "Microsoft.DotNet.Compatibility.ValidatePackage" -- FAILED.

对于我现有的项目,它仍然无法识别重大更改。至少我看到 msbuild 目标被调用了:

Target RunPackageValidation: Using "Microsoft.DotNet.Compatibility.ValidatePackage" task from assembly "C:\Program Files\dotnet\sdk.0.201\Sdks\Microsoft.NET.Sdk\targets..\tools\net472\Microsoft.DotNet.Compatibility.dll". Task "Microsoft.DotNet.Compatibility.ValidatePackage" Done executing task "Microsoft.DotNet.Compatibility.ValidatePackage".

PackageValidation 在我的案例中没有显示任何输出,因为 PackageID 与 AssemblyName 不同。

MS 已修复此问题。参见 https://github.com/dotnet/sdk/issues/23646

我用 prerelease-package 测试过,效果很好 :)