Command-line tool

edit

The Meziantou.Framework.PublicApiGenerator.Tool command-line tool generates the API files of a .dll or .exe that is already built. Use it when you cannot or do not want to change the project, for instance to look at the API of a third-party assembly, or in a build script.

The command reference lists every option of the tool.

Install the tool

dotnet tool install --global Meziantou.Framework.PublicApiGenerator.Tool

Generate the API files

Pass the assembly with --input and the output directory with --output:

Meziantou.Framework.PublicApiGenerator.Tool --input ./bin/Release/net10.0/MyLibrary.dll --output ./public-api

With the default SingleFile layout, this writes public-api/MyLibrary.cs. To choose the path of the file, use --output-file instead of --output:

Meziantou.Framework.PublicApiGenerator.Tool --input ./bin/Release/net10.0/MyLibrary.dll --output-file ./public-api/MyLibrary.PublicApi.cs

To split the API into several files, set the layout. --output is then required, and --output-file is not allowed:

Meziantou.Framework.PublicApiGenerator.Tool --input ./bin/Release/net10.0/MyLibrary.dll --output ./public-api --file-layout OneFilePerNamespace

This writes one file per namespace, such as public-api/Demo.g.cs and public-api/GlobalNamespace.g.cs. See File layouts.

Multi-targeted libraries

Repeat --input once per target framework. The builds are merged into one set of files, with #if blocks for the declarations that differ:

Meziantou.Framework.PublicApiGenerator.Tool --input netstandard2.0=./bin/Release/netstandard2.0/MyLibrary.dll --input net10.0=./bin/Release/net10.0/MyLibrary.dll --output ./public-api

Each input is either path or tfm=path. With a plain path, the target framework is read from the TargetFrameworkAttribute of the assembly; tfm=path sets it explicitly. Two inputs cannot have the same target framework. See Multi-targeted libraries.

Check the API files

Add --verify-no-change to compare the existing files with the assembly instead of writing them, with the same other options as the command that generated them:

Meziantou.Framework.PublicApiGenerator.Tool --input ./bin/Release/net10.0/MyLibrary.dll --output-file ./public-api/MyLibrary.PublicApi.cs --verify-no-change

The command exits with code 1 and lists the files that are out of date, missing or unexpected; it exits with code 0 when the files are up to date. Line endings are ignored. The checks are the same as the ones of the MSBuild package.

Options

OptionDescription
--input <input>Required. The assembly to read, as path or tfm=path. Repeat it for a multi-targeted library.
--output <output>The output directory. Required with the OneFilePerNamespace and OneFilePerType layouts.
--output-file <output-file>The path of the file, with the SingleFile layout only. Use either --output or --output-file.
--file-layout <layout>SingleFile (default), OneFilePerNamespace or OneFilePerType.
--omit-auto-generated-commentOmits the // <auto-generated/> comment at the start of the files.
--verify-no-changeChecks that the files are up to date, without writing anything.
-?, -h, --helpShows the help.
--versionShows the version of the tool.

An invalid combination of options, such as both --output and --output-file, makes the command fail with exit code 1.

Like the MSBuild package, the tool never deletes a file: with a directory layout, the files of removed types stay in the output directory. See Removed types leave files behind.