Repolode
Cysharp

Cysharp/ConsoleAppFramework

A zero-dependency, zero-allocation, AOT-safe C# CLI framework that generates parsing and routing code at compile time via a Source Generator.

Stars
2,234
Forks
130
Open issues
2
Last commit
yesterday

What is it?

ConsoleAppFramework is a C# library for building command-line applications. Instead of relying on attributes and runtime reflection, it analyzes the lambda expressions or methods passed to ConsoleApp.Run and generates the argument parsing and dispatch code at compile time. The result is an application with no runtime dependency on the framework itself, which keeps assembly size small and makes it compatible with Native AOT.

The framework targets .NET 8 with C# 13 and supports synchronous and async commands, multiple and nested commands, and command aliases. Option names default to lower-kebab-case, and option descriptions and aliases come from XML document comments. Help and version output are generated as string constants.

It also includes Ctrl+C handling through CancellationToken, filter (middleware) pipelines, exit code management, DataAnnotations validation, dependency injection for command classes, global options, and parsing via ISpanParsable<T> or JSON.

Key features

  • 01Generates argument parsing and command dispatch code at compile time, with no runtime dependencies.
  • 02Supports Native AOT and avoids reflection and boxing.
  • 03Handles Ctrl+C and SIGTERM through CancellationToken for graceful shutdown.
  • 04Provides filter (middleware) pipelines around command execution.
  • 05Builds help text from XML document comments, including option aliases.
  • 06Supports DataAnnotations validation and dependency injection for command classes.

Use cases

  • Building small, fast-starting CLI tools that need to be published as Native AOT binaries.
  • Organizing a large .NET command-line tool into nested commands with dependency injection.
  • Writing internal batch-style tools that need Ctrl+C-safe cancellation of long-running tasks.

Quick start

  1. 1

    Add the NuGet package to your project

    dotnet add package ConsoleAppFramework
  2. 2

    Call ConsoleApp.Run in your Program with a lambda or method

Things to know

  • Requires .NET 8 or later with C# 13 language version set explicitly for .NET 8 projects.

In collections

Topics

FAQ

What is ConsoleAppFramework?
A zero-dependency, zero-allocation, AOT-safe C# CLI framework that generates parsing and routing code at compile time via a Source Generator. ConsoleAppFramework is a C# library for building command-line applications. Instead of relying on attributes and runtime reflection, it analyzes the lambda expressions or methods passed to ConsoleApp.Run and generates the argument parsing and dispatch code at compile time. The result is an application with no runtime dependency on the framework itself, which keeps assembly size small and makes it compatible with Native AOT.
Is ConsoleAppFramework free to use? What license does it have?
ConsoleAppFramework is open source under the MIT license. Check the license terms before using it in commercial products.
Is ConsoleAppFramework still maintained?
Actively maintained. The last commit to ConsoleAppFramework was on Nov 6, 2026.
What can I use ConsoleAppFramework for?
Building small, fast-starting CLI tools that need to be published as Native AOT binaries. Organizing a large .NET command-line tool into nested commands with dependency injection. Writing internal batch-style tools that need Ctrl+C-safe cancellation of long-running tasks.
How do I install ConsoleAppFramework?
Add the NuGet package to your project: dotnet add package ConsoleAppFramework Call ConsoleApp.Run in your Program with a lambda or method
Where can I get ConsoleAppFramework?
The source code and installation instructions are on GitHub: https://github.com/Cysharp/ConsoleAppFramework

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects