CoreCommandLine 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package CoreCommandLine --version 1.0.6
                    
NuGet\Install-Package CoreCommandLine -Version 1.0.6
                    
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="CoreCommandLine" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CoreCommandLine" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="CoreCommandLine" />
                    
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 CoreCommandLine --version 1.0.6
                    
#r "nuget: CoreCommandLine, 1.0.6"
                    
#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 CoreCommandLine@1.0.6
                    
#: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=CoreCommandLine&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=CoreCommandLine&version=1.0.6
                    
Install as a Cake Tool

Icon

Core Command Line

This is a light-weight dotnet standard 2.1 library, that you can add to your console applications, and create your command line application easily.

How to use

  • Install package from NuGet
  • Create an application by extending the class CommandLineApplication.
  • Add each Command you need, by creating a class which implements ICommand. You can also extend CommandBase instead, so you can make use of some pre implemented and helper methods in it.
  • Introduce each command to your application by using the SubCommand attribute. ex:

  [Subcommands(typeof(FirstCommand),typeof(SecondCommand))]
  public class ExampleApplication:CommandLineApplication{
    ...
  }
  • In your main application entry, instantiate your application and start it.

Please checkout the Example project in repository, for a quick start

Features

  • Simple to use
  • Nested commands (Each command can have its own sub-commands and so on...)
  • Auto generated Help command for each command
  • Can be started as a regular console application OR interactively
  • Supports Dependency Injection

Nested Commands

Each command, can have as many sub commands as needed the same way you added your commands to your application class. For a command to have some sub-commands, you would use Subcommands attribute on parent command and introduce it's child commands.

Argument Commands - Context

Arguments would be child commands that their job is to acquire a value from string[] args for it's parent command. the Context object would be the carrie of this data. the argument-command, processes the args[] object, and saves the result in context. and when parent command gets executed, it can check the context object for it's arguments.

Context

  • public void Set<T>(string key, T value)
    • This method will store a value into the context
  • public T Get<T>(string key, T defaultValue)
    • This method would be used to provide previously stored data from the context.
  • ApplicationExit
    • Setting this property inside any command, would cause the chain of commands to be terminated.
  • InteractiveExit
    • Setting this property inside any command, would close the application when is executed interactively.
    • Usually there is no need to set this manually. When you start your application interactively, and exit command is already added to your commands that would set this property when called. So without any extra coding, you can exit the interactive application just by typing exit.

Command Name And Descriptions

If you implement ICommand class, then you would have to implement Name and Description properties. On the other hand, by extending the CommandBase class, by default these properties would be set from the class name of the command. but you still are able to override these properties.

Application Title - Application Description

There are ApplicationTitle and ApplicationDescription properties in CommandLineApplication class that you can set on instance you create or in the driven class's constructor. These values would be printed when You start your application.

Default output

There is an Output property in Application command which determines the default output method for console application to print out it's output. The Action<string> set into this property, would be delivered to all executing commands to use. If you extend CommandBase class, it's already handled and you can use Output("some-string") inside your driven class (your command) to write on output. And if you implemented the ICommand interface, this output delegate would be delivered to your code when SetOutput(..) method of your command is called before execution.

Logging

In a similar way to Output property, you can set Logger property of your application to make use of your logger of interest. This property is of type ILogger (microsoft's) and can accept any implementation.

NOTE: Using Logger or default Output for printing information towards the user, is up to the developers decision. But the recommended usage would be to use Output for printing execution results and information. And Use logger only for debugging and development logs.

Dependency Injection

To make use of any kind of dependency injection, you just need to provide a facade of your di/ioc resolver by implementing IResolver. Then you can connect your di/ioc by setting the Application's Resolver property to an instance of your IResolver.

by doing so, you can deliver your registered services to your commands by conventional constructor injection easily.

NOTE: In most of ioc/di implementations, you need to register any thing which at some point is supposed to be resolved. since commands with constructor parameters are also being resolved using your resolver, it's so important to REMEMBER TO REGISTER COMMANDS ON YOUR DI REGISTRY. other-wise your commands would not be resolved with resolver, also since they have constructor parameters, they would not be instantiated without a resolver and therefore they will not work.

NOTE: If you use dotnet's builtin di system, you can just simply call application.UseDotnetResolver(serviceProvider) passing an instance of dotnet's IServiceProvider to it.

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 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. 
.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

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
1.1.0-pr06 171 11/4/2025
1.1.0-pr05 166 11/3/2025
1.1.0-pr04 85 10/25/2025
1.1.0-pr03 80 10/25/2025
1.1.0-pr02 145 10/21/2025
1.1.0-pr01 139 10/21/2025
1.0.11 210 10/7/2023
1.0.10 152 10/7/2023
1.0.9 141 10/4/2023
1.0.8 288 3/15/2023
1.0.6 388 12/7/2022
1.0.5 425 12/4/2022
1.0.4 398 12/4/2022
1.0.3 413 11/3/2022
1.0.2 439 11/3/2022