This document contains information regarding API baseline files and how to work with them.
Each project contains two files tracking the public API surface of this project.
This file contains APIs that were released in the last major version.
This file should only be modified after a major release by the maintainers and should never be modified otherwise. There is a script to perform this automatically.
This file contains API changes since the last major version.
There are three types of public API changes that need to be documented.
A new entry needs to be added to the PublicAPI.Unshipped.txt
file for a new API. For example:
#nullable enable
Microsoft.AspNetCore.Builder.NewApplicationBuilder.New() -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
Your IDE should warn you about this case and prompt you to add the new API to PublicAPI.Unshipped.txt
. It will also be displayed as a warning in the build output.
Note: Currently not every IDE supports Code-Fixes provided by a Roslyn Analyzer. Visual Studio Code for example does not at the moment - Visual Studio 2019 does.
A new entry needs to be added to the PublicAPI.Unshipped.txt
file for a removed API. For example:
#nullable enable
*REMOVED*Microsoft.Builder.OldApplicationBuilder.New() -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
This change needs to be done by hand. Copy the relevant line from PublicAPI.Shipped.txt
into PublicAPI.Unshipped.txt
and place *REMOVED*
in front of it.
Two new entries need to be added to the PublicAPI.Unshipped.txt
file for an updated API. One to remove the old API and one for the new API. For example:
#nullable enable
*REMOVED*Microsoft.AspNetCore.DataProtection.Infrastructure.IApplicationDiscriminator.Discriminator.get -> string!
Microsoft.AspNetCore.DataProtection.Infrastructure.IApplicationDiscriminator.Discriminator.get -> string?
The removed case needs to be handled by hand as explained here.
Projects ending in .Tests
or .Resources
are ignored per default.
If you need to manually ignore a project, include the following in its .csproj
file:
<PropertyGroup>
<AddPublicApiAnalyzers>false</AddPublicApiAnalyzers>
</PropertyGroup>
The two text files mentioned above need to be added to each new project.
There is a template file called PublicAPI.empty.txt
in the scripts
directory that can be copied over into a new project.
cp scripts/PublicAPI.empty.txt src/<new-project-folder>/PublicAPI.Shipped.txt
cp scripts/PublicAPI.empty.txt src/<new-project-folder>/PublicAPI.Unshipped.txt
There are three scripts to help you manage the PublicAPI.*.txt
files. They can be found here.
This transfers all changes in the PublicAPI.Unshipped.txt
to the PublicAPI.Shipped.txt
files.
It also takes care of removing lines marked with *REMOVE*
(removals of APIs).
This will output the contents of all PublicAPI.Unshipped.txt
files throughout the project.
This shows all changes of PublicAPI.Shipped.txt
files between git refs. Tags, commit hashes and branch names are supported.
Example:
diff-shipped-api.ps1 -from 11.0.0 -to 12.0.0