SystemCommandLine.Extensions
2.0.0
See the version list below for details.
dotnet add package SystemCommandLine.Extensions --version 2.0.0
NuGet\Install-Package SystemCommandLine.Extensions -Version 2.0.0
<PackageReference Include="SystemCommandLine.Extensions" Version="2.0.0" />
<PackageVersion Include="SystemCommandLine.Extensions" Version="2.0.0" />
<PackageReference Include="SystemCommandLine.Extensions" />
paket add SystemCommandLine.Extensions --version 2.0.0
#r "nuget: SystemCommandLine.Extensions, 2.0.0"
#:package SystemCommandLine.Extensions@2.0.0
#addin nuget:?package=SystemCommandLine.Extensions&version=2.0.0
#tool nuget:?package=SystemCommandLine.Extensions&version=2.0.0
SystemCommandLine.Extensions
Small, pragmatic helpers for building command-line apps with System.CommandLine and the Microsoft.Extensions hosting/DI stack.
- Fluent builders to define options from a typed options class using expressions
- Automatic mapping from parsed command-line values to your options (IOptions<T>)
- DI-first wiring for commands and handlers
- Host-friendly RootCommand setup and ParseResult lifetime integration
- Kebab-case option names by convention (e.g., MyProperty → --my-property)
Install
dotnet add package SystemCommandLine.Extensions
Quick start
Define a command and its options using the builder API and expressions. Implement
IUseCommandBuilder<TCommand> to expose a factory that the DI extensions can use.
using System.CommandLine;
using SystemCommandLine.Extensions;
public class Greet : Command, IUseCommandBuilder<Greet>
{
public Greet(ArgumentMapperRegistration mapperRegistration)
: base("greet", "Greets a person")
{
// Describe options using your options type and expressions
this.UseCommandBuilder().WithMapper<GreetOptions>(mapperRegistration)
.NewOption(o => o.Name).Configure(o =>
{
o.Description = "Name to greet";
o.DefaultValueFactory = _ => "World";
}).AddToCommand()
.NewOption(o => o.Times).Configure(o =>
{
o.Description = "Number of times";
o.DefaultValueFactory = _ => 1;
}).AddToCommand();
}
public static Greet CommandFactory(IServiceProvider sp, ArgumentMapperRegistration mapperRegistration)
=> new(mapperRegistration);
}
public class GreetOptions
{
public string Name { get; set; }
public int Times { get; set; }
}
Wire it up with hosting and DI. The parsed values are bound into IOptions<GreetOptions>.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using System.CommandLine;
using SystemCommandLine.Extensions;
var builder = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
// Root and command registration
services.AddRootCommand<Root>(args);
services.AddCommandWithAsyncHandler<Greet, GreetHandler>();
// Bind parsed command options into IOptions<T>
services.AddBoundToCommandOptions<Greet, GreetOptions>();
});
using IHost host = builder.Start();
ParseResult parse = host.Services.GetRequiredService<ParseResult>();
return await parse.InvokeAsync();
See src/TestConsoleApp for a complete example, including logging integration.
Why use this?
System.CommandLine is powerful but low-level. This library smooths out the most common patterns in real apps:
- Define options once on a POCO and keep them strongly typed end-to-end
- Avoid repetitive glue when mapping parsed values into
IOptions<T> - Compose commands and handlers via DI in a host-friendly way
Requirements
- .NET 8.0+
- System.CommandLine 2.0.0
License
MIT. See LICENSE.txt.
| 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 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 was computed. 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- System.CommandLine (>= 2.0.0)
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 |
|---|---|---|
| 2.0.1-isubcommandof-preview.1 | 144 | 11/23/2025 |
| 2.0.0 | 308 | 11/11/2025 |
| 2.0.0-rc.2.25502.107.1 | 146 | 10/14/2025 |
| 2.0.0-rc.1.25451.107.3 | 181 | 9/20/2025 |
| 2.0.0-rc.1.25451.107.2 | 272 | 9/17/2025 |
| 2.0.0-rc.1.25451.107.1 | 140 | 9/10/2025 |
| 2.0.0-beta7.25380.108.3 | 150 | 9/7/2025 |
| 2.0.0-beta7.25380.108.1 | 69 | 8/23/2025 |
| 2.0.0-beta7.25380.108 | 66 | 8/23/2025 |