![]() |
VOOZH | about |
dotnet add package PublicApiGenerator --version 11.5.4
NuGet\Install-Package PublicApiGenerator -Version 11.5.4
<PackageReference Include="PublicApiGenerator" Version="11.5.4" />
<PackageVersion Include="PublicApiGenerator" Version="11.5.4" />Directory.Packages.props
<PackageReference Include="PublicApiGenerator" />Project file
paket add PublicApiGenerator --version 11.5.4
#r "nuget: PublicApiGenerator, 11.5.4"
#:package PublicApiGenerator@11.5.4
#addin nuget:?package=PublicApiGenerator&version=11.5.4Install as a Cake Addin
#tool nuget:?package=PublicApiGenerator&version=11.5.4Install as a Cake Tool
π Run tests
π Publish preview
π Publish release
π codecov
π Nuget
π Nuget
π GitHub Release Date
π GitHub commits since latest release (by date)
π Size
π GitHub contributors
π Activity
π Activity
π Activity
PublicApiGenerator has no dependencies and simply creates a string that represents the public API. Any approval library can be used to approve the generated public API. Public API approval is often used as an auxiliary tool (often as automated test as shown in the examples below) for tracking intentional or unforeseen changes in public API. At first, public API as string is stored into a text file in VCS. Then the current generated string is compared with one preserved earlier. If they are different, the test ends with an error, indicating the need to make a decision. As a rule, the text file in VCS is updated with a new generated value, while accordingly changing project version - major or minor. Also note that it is normal that sometimes changes in public API do not require changes in minor or major version at all.
PublicApiGenerator supports C# 8 Nullable Reference Types from version 10.
Install-package PublicApiGenerator
Public API of an assembly
var publicApi = typeof(Library).Assembly.GeneratePublicApi();
Public API of multiple types
var myTypes = new[] { typeof(MyType), typeof(YetAnotherType) };
var publicApi = typeof(myTypes).GeneratePublicApi();
Public API of a type
var publicApi = typeof(MyType).GeneratePublicApi();
More control over the API output
var options = new ApiGeneratorOptions { ... };
var publicApi = typeof(Library).Assembly.GeneratePublicApi(options);
[Fact]
public void my_assembly_has_no_public_api_changes()
{
var publicApi = typeof(Library).Assembly.GeneratePublicApi();
var approvedFilePath = "PublicApi.approved.txt";
if (!File.Exists(approvedFilePath))
{
// Create a file to write to.
using (var sw = File.CreateText(approvedFilePath)) { }
}
var approvedApi = File.ReadAllText(approvedFilePath);
Assert.Equal(approvedApi, publicApi);
}
Install-package Shouldly
[Fact]
public void my_assembly_has_no_public_api_changes()
{
var publicApi = typeof(Library).Assembly.GeneratePublicApi();
//Shouldly
publicApi.ShouldMatchApproved();
}
ApiGenerator itself this approach to test API changes.
Install-package ApprovalTests
[Fact]
public void my_assembly_has_no_public_api_changes()
{
var publicApi = typeof(Library).Assembly.GeneratePublicApi();
var writer = new ApprovalTextWriter(publicApi, "txt");
var approvalNamer = new AssemblyPathNamer(assembly.Location);
Approvals.Verify(writer, approvalNamer, Approvals.GetReporter());
}
private class AssemblyPathNamer : UnitTestFrameworkNamer
{
private readonly string name;
public AssemblyPathNamer(string assemblyPath)
{
name = Path.GetFileNameWithoutExtension(assemblyPath);
}
public override string Name
{
get { return name; }
}
}
Install-package Verify.Xunit
[Fact]
public Task my_assembly_has_no_public_api_changes()
{
var publicApi = typeof(Library).Assembly.GeneratePublicApi();
return Verifier.Verify(publicApi);
// Or, if the public api is different based on the target frameworks:
// return Verifier.Verify(publicApi).UniqueForTargetFrameworkAndVersion();
}
Or
Install-package Verify.NUnit
[Test]
public Task my_assembly_has_no_public_api_changes()
{
var publicApi = typeof(Library).Assembly.GeneratePublicApi();
return Verifier.Verify(publicApi);
}
Or
Install-package Verify.MSTest
[TestClass]
public class VerifyObjectSamples :
VerifyBase
{
[TestMethod]
public Task my_assembly_has_no_public_api_changes()
{
var publicApi = typeof(Library).Assembly.GeneratePublicApi();
return Verifier.Verify(publicApi);
}
}
dotnet tool install -g PublicApiGenerator.Tool
dotnet tool update -g PublicApiGenerator.Tool
dotnet tool uninstall -g PublicApiGenerator.Tool
Generate public API for fluent assertions 5.6.0 for runtime framework netcoreapp2.1 and net461
generate-public-api --target-frameworks netcoreapp2.1 net461 --package FluentAssertions --package-version 5.6.0
Generate public API for fluent assertions 5.* for runtime framework net47
generate-public-api --target-frameworks net47 --package FluentAssertions --package-version 5.*
Note that when a single target framework is specified then the API is generated to standard output. To write to a file, you can either use shell redirection:
generate-public-api --target-frameworks net47 --package FluentAssertions --package-version 5.* > api.txt
or specify an output directory to force the generation of an API file:
generate-public-api --target-frameworks net47 --package FluentAssertions --package-version 5.* --output-directory .
Generate public API for fluent assertions 5.6.0 (exact version match) for runtime framework net47
generate-public-api --target-frameworks net47 --package FluentAssertions --package-version [5.6.0]
Generate public API for NServiceBus 7.1.4 for runtime framework netcoreapp2.2 and net452. Note NServiceBus package doesn't contain NServiceBus.dll and therefore it is required to specify the assembly that contains the public API.
generate-public-api --target-frameworks netcoreapp2.2 net452 --package NServiceBus --package-version 7.1.4 --assembly NServiceBus.Core.dll
Generate a public API for NServiceBus release available on myget
generate-public-api --target-frameworks netcoreapp2.2 net452 --package NServiceBus --package-version 7.1.4 --assembly NServiceBus.Core.dll --package-source https://www.myget.org/F/particular/api/v3/index.json
This CLI is driven by System.CommandLine project.
All documentation is available there.
Use generate-public-api --help to display help page.
--target-frameworks framework1 framework2 framework3
The target framework in which the package will be restored. The target framework is also used as runtime to generate the public API. It is required to specify a valid runtime framework. For example
netcoreapp2.2 net452 to build a public API for netcoreapp2.2 and net452netcoreapp2.1 net461 to build a public API for netcoreapp2.1 and net461net47 to build a public API for net47It is not possible to use netstandard2.0 because it is not a valid runtime framework.
If only a single target framework is given then the API is generated to the standard output unless the --output-directory option is also specified.
--package PackageName
A valid nuget package name. For example
When the --package switch is used the --package-version switch is mandatory.
--package-version Version
A nuget package version or floating versions as specified by https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files and https://docs.microsoft.com/en-us/nuget/concepts/package-versioning#version-ranges-and-wildcards. For example
--package-source Source
Allows specifying one or multiple package sources to look for packages.
--assembly Assembly.dll
The assembly name including the extension to generate a public API from in case in differs from the package name. For example
--project-path
A path to a csproj file that contains the public API that needs to be built. By default a release build will be generated. When the project-path switch is used it is required to specify the --assembly switch to point to the output assembly that contains the public API. For example
..\PublicApiGenerator\PublicApiGenerator.csproj--working-directory Path
The temporary working directory to be used to generate the work artifacts.
--output-directory Path
The output directory where public API text-files should be moved. The end with *.received.txt
--generator-version Version
By default latest stable release version of PubliApiGenerator will be used in the global tool to generate the public API with in the major range of the global tool. It is possible to override the PublicApiGenerator version by specifying the version to be used in this switch. For example
--verbose
Prints to stderr detailed information about what's going on behind the scenes.
--leave-artifacts
For troubleshooting purposes it might be necessary to look into the temporary work artifacts. By specifying this switch the temporary csproj files and all the temp folders are not deleted after a run. Be aware this might significantly decrease the available disk space because all artifacts including the compile time artifacts are not deleted.
--wait-time-in-seconds
The number of seconds to wait for the API generation process to end (default 60 seconds). If multiple target frameworks are used the wait time is applied per target framework. If the process did not end in the allotted time a TimeoutException is thrown.
--settings-file
Json file with options in form of ApiGeneratorOptions class.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on PublicApiGenerator:
| Package | Downloads |
|---|---|
|
ApiApprover
Simply add this package to add a test which generates a string of your public API, then sends it to Approval Tests to approve any public API changes. Don't accidently miss a breaking API change and break semantic versioning again. |
|
|
MintPlayer.Verz.Targets
Package Description |
Showing the top 20 popular GitHub repositories that depend on PublicApiGenerator:
| Repository | Stars |
|---|---|
|
spectreconsole/spectre.console
A .NET library that makes it easier to create beautiful console applications.
|
|
|
Humanizr/Humanizer
Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities
|
|
|
reactiveui/refit
The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface.
|
|
|
reactiveui/ReactiveUI
An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.
|
|
|
serilog/serilog
Simple .NET logging with fully-structured events
|
|
|
dotnet/reactive
The Reactive Extensions for .NET
|
|
|
graphql-dotnet/graphql-dotnet
GraphQL for .NET
|
|
|
Shane32/QRCoder
A pure C# Open Source QR Code implementation
|
|
|
akkadotnet/akka.net
Canonical actor model implementation for .NET with local + distributed actors in C# and F#.
|
|
|
BililiveRecorder/BililiveRecorder
ε½ζ姬 | mikufans ηζΎιε½εΆ
|
|
|
Xabaril/AspNetCore.Diagnostics.HealthChecks
Enterprise HealthChecks for ASP.NET Core Diagnostics Package
|
|
|
riok/mapperly
A .NET source generator for generating object mappings. No runtime reflection.
|
|
|
thomhurst/TUnit
A modern, fast and flexible .NET testing framework
|
|
|
fluentassertions/fluentassertions
A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, as well as .NET Core 2.1, .NET Core 3.0, .NET 6, .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.
|
|
|
oskardudycz/EventSourcing.NetCore
Examples and Tutorials of Event Sourcing in .NET
|
|
|
VerifyTests/Verify
Verify is a snapshot testing tool that simplifies the assertion of complex data models and documents.
|
|
|
shouldly/shouldly
Should testing for .NETβthe way assertions should be!
|
|
|
EasyNetQ/EasyNetQ
An easy to use .NET API for RabbitMQ
|
|
|
DbUp/DbUp
DbUp is a .NET library that helps you to deploy changes to SQL Server databases. It tracks which SQL scripts have been run already, and runs the change scripts that are needed to get your database up to date.
|
|
|
castleproject/Core
Castle Core, including Castle DynamicProxy, Logging Services and DictionaryAdapter
|
| Version | Downloads | Last Updated |
|---|---|---|
| 11.5.4 | 497,473 | 12/6/2025 |
| 11.5.3 | 32,084 | 11/26/2025 |
| 11.5.2 | 2,373 | 11/25/2025 |
| 11.5.1 | 12,391 | 11/19/2025 |
| 11.5.0 | 73,819 | 10/13/2025 |
| 11.4.6 | 238,411 | 4/23/2025 |
| 11.4.5 | 78,901 | 3/1/2025 |
| 11.4.4 | 5,581 | 3/1/2025 |
| 11.4.3 | 5,513 | 3/1/2025 |
| 11.4.2 | 21,026 | 2/15/2025 |
| 11.4.1 | 45,724 | 1/29/2025 |
| 11.4.0 | 9,632 | 1/25/2025 |
| 11.3.0 | 73,296 | 12/17/2024 |
| 11.2.0 | 90,250 | 12/11/2024 |
| 11.1.0 | 817,768 | 12/3/2023 |
| 11.0.0 | 275,316 | 3/6/2023 |
| 10.5.0 | 1,320 | 3/6/2023 |
| 10.4.1 | 744 | 3/6/2023 |
| 10.4.0 | 770 | 3/6/2023 |
| 10.3.0 | 292,694 | 1/31/2022 |