Commanda 0.3.1
dotnet add package Commanda --version 0.3.1
NuGet\Install-Package Commanda -Version 0.3.1
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="Commanda" Version="0.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Commanda" Version="0.3.1" />
<PackageReference Include="Commanda" />
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 Commanda --version 0.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Commanda, 0.3.1"
#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 Commanda@0.3.1
#: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=Commanda&version=0.3.1
#tool nuget:?package=Commanda&version=0.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Commanda
A lightweight, Cocona-like command line builder for .NET, combining System.CommandLine with the Generic Host (HostBuilder).
Supported target frameworks: net8.0, net9.0, net10.0.
Features
- Fluent registration via
IHostApplicationBuilder - Delegate-based command handlers (sync or async)
- DI parameter injection for reference type parameters
- Automatic binding of primitive/string parameters from CLI
- Support for default help output from System.CommandLine
- Attribute-based options via
[Option](alias inference, descriptions, bool flags)
Quick Start
using Microsoft.Extensions.Hosting;
using Commanda;
var builder = Host.CreateApplicationBuilder(args);
builder.AddCommand("greet", "Say hello", (string name) =>
{
Console.WriteLine($"Hello, {name}!");
});
builder.AddCommand("sum", (int a, int b) =>
{
Console.WriteLine(a + b);
});
var app = builder.Build();
await app.RunCommandsAsync(args);
Run:
dotnet run --project examples/Commanda.Example -- greet Alice
dotnet run --project examples/Commanda.Example -- sum 2 5
Dependency Injection
Any non-primitive, non-string parameter will be resolved from the host service provider.
builder.Services.AddSingleton<GreetingService>();
builder.AddCommand("hello", (GreetingService svc) => svc.SayHello());
Attribute-Based Options
Use [Option] on parameters to turn them into named options with help descriptions. Parameters without [Option] remain positional arguments.
Rules:
- Alias: If
Nameis not specified, the long alias is inferred from the parameter name in kebab-case (e.g.,containerName→--container-name). - Description: Use
Descriptionto populate help text. - Required vs optional: Parameters without a default are required; parameters with a default become optional and use the default when omitted.
- Bool flags:
[Option] boolacts as a switch; presence setstrue. You can also pass--flag falseto override. Default isfalseunless a parameter default is provided.
Example:
builder.AddCommand("hello-opt", async (
GreetingService svc,
[Option(Description = "Name to greet")] string name,
[Option("excited", Description = "Add exclamation (default false)")] bool excited = false
) =>
{
await svc.SayHelloAsync(name);
if (excited) Console.WriteLine("!");
});
Try it:
dotnet run --project examples/Commanda.Example -- hello-opt --name Alice
dotnet run --project examples/Commanda.Example -- hello-opt --name Bob --excited
Changelog
See CHANGELOG.md.
Roadmap / Future Enhancements
- Attribute-based command & option metadata
- Sub-commands via grouped classes
- Validation (DataAnnotations)
- Source generator for AOT friendliness
- Middleware / pipeline hooks
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.Hosting (>= 10.0.3)
- System.CommandLine (>= 2.0.3)
-
net8.0
- Microsoft.Extensions.Hosting (>= 8.0.1)
- System.CommandLine (>= 2.0.3)
-
net9.0
- Microsoft.Extensions.Hosting (>= 9.0.13)
- System.CommandLine (>= 2.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.3.1 | 50 | 2/28/2026 |
| 0.3.0 | 112 | 1/17/2026 |
| 0.3.0-rc-0001 | 79 | 1/17/2026 |
| 0.2.0 | 128 | 1/17/2026 |