Albatross.CommandLine 9.0.0

Prefix Reserved
dotnet add package Albatross.CommandLine --version 9.0.0
                    
NuGet\Install-Package Albatross.CommandLine -Version 9.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Albatross.CommandLine" Version="9.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Albatross.CommandLine" Version="9.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Albatross.CommandLine" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Albatross.CommandLine --version 9.0.0
                    
#r "nuget: Albatross.CommandLine, 9.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Albatross.CommandLine@9.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Albatross.CommandLine&version=9.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Albatross.CommandLine&version=9.0.0
                    
Install as a Cake Tool

Albatross.CommandLine

A .NET library that simplifies creating command-line applications with System.CommandLine. It provides automatic code generation and dependency injection support while maintaining full access to System.CommandLine's capabilities. The framework is opinionated toward async actions with out-of-the-box support for cancellation and graceful shutdown.

Designed for enterprise CLI applications, Albatross.CommandLine enforces consistent async patterns, built-in dependency injection, and graceful shutdown handling. These opinionated choices reduce complexity and ensure scalability from simple utilities to complex enterprise workflows.

Key Features

  • Minimal Boilerplate - Attribute-based command definition with automatic code generation
  • AOT-compatible - Uses compile-time Roslyn source generation (no runtime reflection or emit), making it friendly to Native AOT scenarios
  • Dependency Injection - Built-in DI container integration
  • Minimum Dependencies - Only depends on System.CommandLine and Microsoft.Extensions.Hosting.
  • Full Flexibility - Direct access to System.CommandLine when needed
  • Cancellation & Graceful Shutdown - Built-in support for Ctrl+C interruption via cancellation tokens and graceful shutdown handling
  • Reusable Parameter - Create customized Option and Argument classes and use [UseOption<T>] and [UseArgument<T>] attributes to compose them into commands with automatic code generation
  • Advanced Option Handlers - Injectable async option handlers with [OptionHandler] attribute for pre-processing and input transformation patterns. Execute database validation, API calls, or transform simple inputs into complex objects before command execution
  • Easy Extensions - Use CommandHost.ConfigureHost() to bootstrap additional services, or use Albatross.CommandLine.Defaults for pre-configured Serilog logging and JSON/environment configuration support

Quick Start

Bootstrapping

Create a console app. In the program.cs file, insert the code below:

using MyApp.AutoGenerated;   // generated RegisterCommands()/AddCommands() live in <RootNamespace>.AutoGenerated

internal class Program {
    static async Task<int> Main(string[] args) {
        await using var host = new CommandHost("Sample Command Line Application")
            .RegisterServices(RegisterServices)
            // this method is generated by source generator
            // this line will not compile before the creation of the first command
            .AddCommands()
            .Parse(args)
            .Build();
        return await host.InvokeAsync();
    }
    static void RegisterServices(ParseResult result, IConfiguration configuration, IServiceCollection services) {
            // RegisterCommands method is generated by codegen
            services.RegisterCommands();
            // register the rest of the dependency here
            ...
        }
    }

Define a Verb

[Verb<HelloWorldCommandHandler>("hello", Description = "The HelloWorld command")]
public record class HelloWorldParams {
    [Option]
    public required string Name { get; init; }
}

Create the Command Handler

The Command Handler has to inherit interface: IAsyncCommandHandler

public class HelloWorldCommandHandler : IAsyncCommandHandler {
    ParseResult result;
    HelloWorldParams parameters;
    ILogger logger;
    
    public HelloWorldCommandHandler(ParseResult result, HelloWorldParams parameters, ILogger<HelloWorldCommandHandler> logger) {
        this.result = result;
        this.parameters = parameters;
        this.logger = logger;
    }
    public async Task<int> InvokeAsync(CancellationToken cancellationToken) {
        // do your work here
        await Console.WriteLineAsync($"{result} is invoked with {parameters}");
        return 0;
    }
}

Run the app

Usage: dotnet run -- hello --name test

Dependencies

  • System.CommandLine 3.0.0+
  • Microsoft.Extensions.Hosting 10.0.15+

Prerequisites

  • C# Compiler 4.10.0+ (included with .NET 8 SDK)

📖 Documentation

📚 Complete Documentation

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Albatross.CommandLine:

Package Downloads
Albatross.CommandLine.Defaults

Opinionated defaults for Albatross.CommandLine apps: JSON configuration and file-based Serilog logging, added with a single WithDefaults() call.

Albatross.CommandLine.Inputs

Reusable System.CommandLine options and arguments for Albatross.CommandLine apps: validated file and directory paths, time zone, confirmation, and tracker files.

Albatross.EFCore.Admin

Package Description

Albatross.CommandLine.Outputs

Stable JSON output for Albatross.CommandLine apps: a CommandOutput result envelope, Print and PrintAsync rendering, a --compact option, and an opt-in global error handler.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.0 0 11/25/2026
9.0.0-rc.294 76 11/16/2026
9.0.0-rc.288 131 10/14/2026
9.0.0-rc.284 813 7/24/2026
9.0.0-rc.281 109 7/17/2026
9.0.0-rc.270 158 7/13/2026
8.0.14 1,045 5/30/2026
8.0.12 129 5/8/2026
8.0.11 113 5/1/2026
8.0.10 336 3/21/2026
8.0.8 121 2/23/2026
8.0.7 178 1/26/2026
8.0.6 113 1/23/2026
8.0.5 111 1/22/2026
8.0.4 103 1/21/2026
8.0.3 101 1/16/2026
Loading failed