This project uses .NET Package Validation to detect breaking changes between versions.
The Moq.AutoMock.csproj file includes package validation settings:
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>3.6.0</PackageValidationBaselineVersion>When you run dotnet pack, the tooling compares the current build against the baseline version (3.6.0) to detect:
- Breaking API changes (removed or modified methods, properties, types)
- Dropped target framework support
- Binary compatibility issues
If you encounter a CP0002 error during dotnet pack, it means you've introduced a breaking change:
error CP0002: Member 'X.Y.Method(...)' exists on [Baseline] lib/netstandard2.0/Moq.AutoMock.dll but not on lib/netstandard2.0/Moq.AutoMock.dll
Refactor your code to maintain backward compatibility:
- Add overloads instead of changing method signatures
- Mark members as
[Obsolete]before removal - Use optional parameters carefully (they can be binary breaking)
If you need to introduce a breaking change (e.g., for a major version release):
-
Generate a suppression file:
dotnet pack /p:GenerateCompatibilitySuppressionFile=true
-
This creates/updates
CompatibilitySuppressions.xmlwith entries for each breaking change:<Suppression> <DiagnosticId>CP0002</DiagnosticId> <Target>M:Moq.AutoMock.SomeClass.SomeMethod(...)</Target> <IsBaselineSuppression>true</IsBaselineSuppression> </Suppression>
-
Review and commit the
CompatibilitySuppressions.xmlfile to document the breaking changes in your PR. -
After releasing the new version, update the baseline:
- Delete or clear
CompatibilitySuppressions.xml - Update
PackageValidationBaselineVersionto the new released version
- Delete or clear
After releasing a new version (e.g., 3.7.0), update the baseline in Moq.AutoMock.csproj:
<PackageValidationBaselineVersion>3.7.0</PackageValidationBaselineVersion>This ensures future changes are validated against the latest stable release.