|
| 1 | +--- |
| 2 | +parent: Packaging |
| 3 | +ancestor: Rules |
| 4 | +--- |
| 5 | + |
| 6 | +# Proj0250: Generate API compatibility suppression file |
| 7 | +When [package validation](https://learn.microsoft.com/en-us/dotnet/fundamentals/apicompat/package-validation/overview) is enabled, it is required to |
| 8 | +provide a [suppression file](https://learn.microsoft.com/en-us/dotnet/fundamentals/apicompat/diagnostic-ids#how-to-suppress) for all differences that |
| 9 | +occur in the API: |
| 10 | +- [Changes between different package versions](https://learn.microsoft.com/en-us/dotnet/fundamentals/apicompat/package-validation/baseline-version-validator) |
| 11 | +- [Differences between different runtimes (e.g. windows vs unix)](https://learn.microsoft.com/en-us/dotnet/fundamentals/apicompat/package-validation/compatible-framework-validator) |
| 12 | +- [Differences between different target frameworks (e.g. netstandard2.0 vs net8.0)](https://learn.microsoft.com/en-us/dotnet/fundamentals/apicompat/package-validation/compatible-framework-in-package-validator) |
| 13 | + |
| 14 | +This suppression file can be created manually, or automatically generated |
| 15 | +by enabling the `GenerateCompatibilitySuppressionFile` property. It is advised |
| 16 | +to enable this property in the project file to ensure that the file is kept |
| 17 | +up-to-date automatically. |
| 18 | + |
| 19 | +Additionally, it is advised to keep changes to the generated file tracked in |
| 20 | +your version control system to ensure any API changes are explicitly included |
| 21 | +in code reviews. |
| 22 | + |
| 23 | +More information can be found [here](https://learn.microsoft.com/en-us/dotnet/fundamentals/apicompat/package-validation/overview), [here](https://learn.microsoft.com/en-us/dotnet/fundamentals/apicompat/diagnostic-ids#how-to-suppress) and [here](https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#apicompatgeneratesuppressionfile). |
| 24 | + |
| 25 | +## Non-compliant |
| 26 | +``` xml |
| 27 | +<Project Sdk="Microsoft.NET.Sdk"> |
| 28 | + |
| 29 | + <PropertyGroup> |
| 30 | + <TargetFramework>net8.0</TargetFramework> |
| 31 | + <EnablePackageValidation>true</EnablePackageValidation> |
| 32 | + <ApiCompatGenerateSuppressionFile>false</ApiCompatGenerateSuppressionFile> |
| 33 | + </PropertyGroup> |
| 34 | + |
| 35 | +</Project> |
| 36 | +``` |
| 37 | + |
| 38 | +Or: |
| 39 | + |
| 40 | +``` xml |
| 41 | +<Project Sdk="Microsoft.NET.Sdk"> |
| 42 | + |
| 43 | + <PropertyGroup> |
| 44 | + <TargetFramework>net8.0</TargetFramework> |
| 45 | + <EnablePackageValidation>true</EnablePackageValidation> |
| 46 | + </PropertyGroup> |
| 47 | + |
| 48 | +</Project> |
| 49 | +``` |
| 50 | + |
| 51 | +## Compliant |
| 52 | +``` xml |
| 53 | +<Project Sdk="Microsoft.NET.Sdk"> |
| 54 | + |
| 55 | + <PropertyGroup> |
| 56 | + <TargetFramework>net8.0</TargetFramework> |
| 57 | + <EnablePackageValidation>true</EnablePackageValidation> |
| 58 | + <ApiCompatGenerateSuppressionFile>true</ApiCompatGenerateSuppressionFile> |
| 59 | + </PropertyGroup> |
| 60 | + |
| 61 | +</Project> |
| 62 | +``` |
0 commit comments