Skip to content

Enable package validation with baseline comparison - #1671

Merged
MichaelSimons merged 7 commits into
dotnet:mainfrom
MichaelSimons:michaelsimons/enable-package-validation
May 27, 2026
Merged

MichaelSimons merged 7 commits into
dotnet:mainfrom
MichaelSimons:michaelsimons/enable-package-validation

Conversation

@MichaelSimons

@MichaelSimons MichaelSimons commented May 20, 2026 •

Copy link
Copy Markdown
Member

Enables package validation (API compat) for reference packages and targeting packs, comparing the built packages against their upstream NuGet baseline to ensure public API surface compatibility.

Fixes #1424

What this does

  • Enables EnablePackageValidation with baseline comparison in eng/PackageValidation.targets
  • Adds eng/ExcludeTargetFrameworks.props as the single source of truth for TFMs that source-build doesn't include, shared by both the package source generator and package validation
  • Configures PackageValidationBaselineFrameworkToIgnore to skip baseline comparisons for excluded TFMs, eliminating false-positive CP0001 errors for TFMs we intentionally don't build
  • Enables strict mode for baseline validation so real API breaks (type removals, renames) are caught
  • Adds CompatibilitySuppressions.xml files for packages where the generator produces known differences from the baseline
  • Updates documentation (README and copilot instructions) with the API compat workflow

Suppressions

Diagnostic Count Affected packages
CP0021 — Missing notnull generic constraint 612 system.collections.immutable, system.text.json, microsoft.extensions.*
CP0008 — Missing interfaces 25 microsoft.build, microsoft.build.utilities.core
CP0002 — Missing event accessor members 4 microsoft.build
CP0001 — Missing types 2 system.configuration.configurationmanager (needs investigation)

Enables package validation (API compat) for reference packages and targeting packs,
comparing the built packages against their upstream NuGet baseline to ensure public
API surface compatibility.

- Enable EnablePackageValidation with baseline comparison in eng/PackageValidation.targets
- Add eng/ExcludeTargetFrameworks.props as single source of truth for TFMs that
  source-build doesn't include, shared by generator and package validation
- Configure PackageValidationBaselineFrameworkToIgnore to skip baseline comparisons
  for excluded TFMs
- Enable strict mode for baseline validation to catch real API breaks
- Add CompatibilitySuppressions.xml files for known generator differences
- Update documentation (README and copilot instructions) with API compat workflow

Fixes dotnet#1424

Co-authored-by: Copilot <[email protected]>
@MichaelSimons
MichaelSimons requested a review from a team as a code owner May 20, 2026 17:07
@MichaelSimons
MichaelSimons requested a review from ViktorHofer May 20, 2026 17:09
MichaelSimons and others added 2 commits May 20, 2026 17:25
microsoft.extensions.hosting.abstractions/10.0.0 was removed in dotnet#1666 as an
unreferenced package. The suppression file should not have been added back.

Co-authored-by: Copilot <[email protected]>
Comment thread eng/ExcludeTargetFrameworks.props Resolved
Comment thread eng/PackageValidation.targets Resolved
Comment thread eng/PackageValidation.targets Resolved

@ViktorHofer ViktorHofer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Do you understand the compatibility differences? LLM might be able to summarize them. I'm curious about anything that stands out that would indicate a misconfiguration in this repo or something that GenAPI should do differently.

MichaelSimons and others added 2 commits May 26, 2026 18:22
…escaping

Address code review feedback by simplifying and consolidating the excluded
target frameworks infrastructure:

**Key Changes:**

1. **Single source of truth**: Replaced duplicate ExcludeTargetFrameworks and
   ExcludeTargetFrameworksMSBuildEscaped properties with a single ItemGroup
   definition in Directory.Build.props

2. **Consistent escaping**: Use MSBuild::Escape() uniformly on all items for
   readability and maintainability, even for literals that don't contain wildcards

3. **Proper separation of concerns**: Refactored GetPackageItems task to accept
   ITaskItem[] and convert to string[] before passing to TargetFrameworkRegexFilter,
   which now accepts IEnumerable<string> (pure logic, no MSBuild dependencies)

4. **Removed dead code**: Eliminated unused string-based constructor and helper
   methods from TargetFrameworkRegexFilter

5. **Simplified file structure**: Deleted eng/ExcludeTargetFrameworks.props as
   the list is now centralized in Directory.Build.props

6. **Removed unnecessary condition**: Simplified package validation logic in
   eng/PackageValidation.targets

**Benefits:**
- No duplication - single list maintained in one place
- Better readability - wildcards visible with MSBuild::Escape('pattern*')
- Cleaner architecture - logic layer decoupled from MSBuild
- More efficient - deferred LINQ execution, single array allocation

Co-authored-by: Copilot <[email protected]>
Document the specific API compatibility issues being suppressed:
- CP0001: Stub type added for netstandard2.0 compilation
- CP0002: Missing event accessor members (add_/remove_)
- CP0008: Missing [Serializable] attribute
- CP0021: Missing notnull generic constraint on return type

Co-authored-by: Copilot <[email protected]>
@MichaelSimons
MichaelSimons force-pushed the michaelsimons/enable-package-validation branch from 27caaf1 to 113007f Compare May 26, 2026 18:43
MichaelSimons and others added 2 commits May 26, 2026 19:31
Changed CP0008 suppression comments from "[Serializable] attribute" to
the actual missing interfaces: IMetadataContainer, ITranslatable, and
IBuildCheckResult.

Co-authored-by: Copilot <[email protected]>
@MichaelSimons

MichaelSimons commented May 26, 2026 •

Copy link
Copy Markdown
Member Author

This looks good. Do you understand the compatibility differences? LLM might be able to summarize them. I'm curious about anything that stands out that would indicate a misconfiguration in this repo or something that GenAPI should do differently.

From my investigation compliments of LLM, I logged the following issues:

@MichaelSimons

Copy link
Copy Markdown
Member Author

FYI, I logged one more genapi issue - dotnet/sdk#54464

@MichaelSimons
MichaelSimons merged commit c326072 into dotnet:main May 27, 2026
4 checks passed
@MichaelSimons
MichaelSimons deleted the michaelsimons/enable-package-validation branch May 27, 2026 13:13
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run PackageValidation to ensure that produced packages are public API identical with upstream versions

3 participants