Ookii.CommandLine 3.0.0

.NET 6.0 .NET Standard 2.0
dotnet add package Ookii.CommandLine --version 3.0.0
NuGet\Install-Package Ookii.CommandLine -Version 3.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="Ookii.CommandLine" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ookii.CommandLine --version 3.0.0
#r "nuget: Ookii.CommandLine, 3.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Ookii.CommandLine as a Cake Addin
#addin nuget:?package=Ookii.CommandLine&version=3.0.0

// Install Ookii.CommandLine as a Cake Tool
#tool nuget:?package=Ookii.CommandLine&version=3.0.0


Ookii.CommandLine is a powerful and flexible command line argument parsing library for .Net applications.

  • Easily define arguments by creating a class with properties.
  • Create applications with multiple subcommands.
  • Generate fully customizable usage help.
  • Supports PowerShell-like and POSIX-like parsing rules.

Ookii.CommandLine is provided in versions for .Net Standard 2.0, .Net Standard 2.1, and .Net 6.0 and later


Ookii.CommandLine is a library that lets you parse the command line arguments for your application into a set of strongly-typed, named values. You can easily define the accepted arguments, and then parse the command line supplied to your application for those arguments. In addition, you can generate usage help that can be displayed to the user.

Ookii.CommandLine can be used with any kind of .Net application, whether console or GUI. Some functions, such as creating usage help, are primarily designed for console applications, but even those can be easily adapted for use with other styles of applications.

Two styles of command line parsing rules are supported: the default mode uses rules similar to those used by PowerShell, and the alternative long/short mode uses a style influenced by POSIX conventions, where arguments have separate long and short names with different prefixes. Many aspects of the parsing rules are configurable.

To determine which arguments are accepted, you create a class, with constructor parameters and properties that define the arguments. Attributes are used to specify names, create required or positional arguments, and to specify descriptions for use in the generated usage help.

For example, the following class defines four arguments: a required positional argument, an optional positional argument, a named-only argument, and a switch argument (sometimes also called a flag):

class MyArguments
    [CommandLineArgument(Position = 0, IsRequired = true)]
    [Description("A required positional argument.")]
    public string? Required { get; set; }

    [CommandLineArgument(Position = 1)]
    [Description("An optional positional argument.")]
    public int Optional { get; set; }

    [Description("An argument that can only supplied by name.")]
    public DateTime Named { get; set; }

    [Description("A switch argument, which doesn't require a value.")]
    public bool Switch { get; set; }

Each argument has a different type that determines the kinds of values it can accept.

To parse these arguments, all you have to do is add the following line to your Main method:

var arguments = CommandLineParser.Parse<MyArguments>();

This code will take the arguments from Environment.GetCommandLineArgs() (you can also manually pass a string[] array if you want), will handle and print errors to the console, and will print usage help if needed. It returns an instance of MyArguments if successful, and null if not.

If the arguments are invalid, or help is requested, this application will print the following usage help:

Usage: MyApplication [-Required] <String> [[-Optional] <Int32>] [-Help] [-Named <DateTime>]
   [-Switch] [-Version]

    -Required <String>
        A required positional argument.

    -Optional <Int32>
        An optional positional argument.

    -Help [<Boolean>] (-?, -h)
        Displays this help message.

    -Named <DateTime>
        An argument that can only supplied by name.

    -Switch [<Boolean>]
        A switch argument, which doesn't require a value.

    -Version [<Boolean>]
        Displays version information.

The usage help includes the descriptions given for the arguments.

The application also has two arguments that weren't in the class, -Help and -Version, which are automatically added by default.

An example invocation of this application, specifying all the arguments, would look like this (argument names are case insensitive by default):

./MyApplication foo 42 -switch -named 2022-08-14

In addition, Ookii.CommandLine can be used to create applications that have multiple subcommands, each with their own arguments.

For more information, including a tutorial and samples, see the full documentation on GitHub.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Ookii.CommandLine:

Package Downloads

A sample for Ookii.CommandLine demonstrating how to define and parse arguments. The sample is provided for C# and Visual Basic.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Ookii.CommandLine:

Repository Stars
Pure C# IL Intepreter Runtime, which is fast and reliable for scripting requirement on enviorments, where jitting isn't possible.
Version Downloads Last updated
3.0.0 89 12/1/2022
2.4.0 428 9/1/2022
2.3.0 16,485 9/5/2019
2.2.0 82,864 2/6/2013
2.1.0 2,408 2/20/2012

This version contains breaking changes compared to version 2.x. For details, please view: https://www.ookii.org/Link/CommandLineVersionHistory