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

Time:04-19

I have a .NET project that creates a nuget package and I wanted to add PackageValidation as described here: https://docs.microsoft.com/en-us/dotnet/fundamentals/package-validation/overview

I have these lines in my sdk-style project file:

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

But I don't get any output, even if I add breaking changes to my assembly.

Only when I change the BaseLineVersion to a number that does not exist, I see some related output:

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

Does anybody have the .net package validation working?

Update: I created a new .NET 6 project to test, published a package with version 1.0.0, increased my version to 1.0.1 and made a breaking change to the library. Then I get this message when building:

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

Why does this not work with my existing project???

Update2: Did some more testing and validation works with new projects in .Net6, .net standard 2.0 and .net 4.8.

For my new .net 4.8 project I see this in the output after adding a breaking change:

Target RunPackageValidation: Using "Microsoft.DotNet.Compatibility.ValidatePackage" task from assembly "C:\Program Files\dotnet\sdk\6.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\6.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.

For my existing project it still does not recognize the breaking change. At least I see that the msbuild target gets called:

Target RunPackageValidation: Using "Microsoft.DotNet.Compatibility.ValidatePackage" task from assembly "C:\Program Files\dotnet\sdk\6.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".

CodePudding user response:

PackageValidation did not show any output in my case, because the PackageID is different than the AssemblyName.

This is already fixed by MS. See https://github.com/dotnet/sdk/issues/23646

I tested with a prerelease-package and this works fine :)

  • Related