Optionus 0.9.0

dotnet add package Optionus --version 0.9.0
                    
NuGet\Install-Package Optionus -Version 0.9.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="Optionus" Version="0.9.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Optionus" Version="0.9.0" />
                    
Directory.Packages.props
<PackageReference Include="Optionus" />
                    
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 Optionus --version 0.9.0
                    
#r "nuget: Optionus, 0.9.0"
                    
#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 Optionus@0.9.0
                    
#: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=Optionus&version=0.9.0
                    
Install as a Cake Addin
#tool nuget:?package=Optionus&version=0.9.0
                    
Install as a Cake Tool

Optionus

A small, dependency-free command-line option parser for .NET, in the style of Perl's Getopt::Long.

Optionus is a maintained fork of Mono.Options, which itself grew out of NDesk.Options. Both upstream projects are no longer actively maintained. Optionus keeps the API and behaviour, targets current .NET, and fixes a few long-standing issues.

Authors and credits

Optionus is based on the work of the original authors:

  • Jonathan Pryor: original author of NDesk.Options and Mono.Options
  • Federico Di Gregorio: contributor
  • Rolf Bjarne Kvinge: contributor (Xamarin)
  • Novell, Xamarin Inc and Microsoft Corporation: copyright holders of the upstream code

Fork maintained by vdasus.

Features

  • Single source file, no dependencies
  • Option prototypes: "v|verbose", "n|name=" (required value), "l|level:" (optional value)
  • Short, long and Windows-style prefixes: -v, --verbose, /verbose
  • Values as -n=foo, -n:foo, -n foo
  • Bundling: -abc is the same as -a -b -c; -Dname=value
  • Boolean switches: -x+ / -x-
  • Typed values through TypeConverter: int, enum, Nullable<T>, custom types
  • Key/value options: -Dkey=value
  • -- stops option processing
  • Response files: @args.txt
  • Generated help text: WriteOptionDescriptions
  • Git-style sub-commands with CommandSet and Command

Target frameworks

  • netstandard2.0 (.NET Framework 4.6.1+, .NET Core 2.0+, Mono)
  • net10.0

Installation

dotnet add package Optionus

Quick start

using Optionus;

bool showHelp = false;
int verbosity = 0;
string? output = null;
var names = new List<string>();

var options = new OptionSet {
    "Usage: greet [OPTIONS]+ NAME...",
    "",
    "Options:",
    { "n|name=", "the {NAME} to greet", v => names.Add(v) },
    { "o|output=", "write to {FILE}", v => output = v },
    { "v", "increase verbosity", v => { if (v != null) ++verbosity; } },
    { "h|help", "show this message and exit", v => showHelp = v != null },
};

List<string> extra;
try {
    extra = options.Parse(args);
}
catch (OptionException e) {
    Console.Error.WriteLine($"greet: {e.Message}");
    Console.Error.WriteLine("Try `greet --help' for more information.");
    return 1;
}

if (showHelp) {
    options.WriteOptionDescriptions(Console.Out);
    return 0;
}

Parse returns the arguments it did not consume.

Sub-commands

var suite = new CommandSet("tool") {
    "usage: tool COMMAND [OPTIONS]+",
    new Command("build", "Build the project") {
        Options = new OptionSet { { "c|configuration=", v => configuration = v } },
        Run = args => Build(args),
    },
};
return suite.Run(args);

tool help and tool help build are provided automatically.

Migrating from NDesk.Options or Mono.Options

Replace the package reference and the namespace:

- using NDesk.Options;
- using Mono.Options;
+ using Optionus;

The public API is otherwise unchanged.

Changes compared to Mono.Options

  • Namespace Optionus; SDK-style project for netstandard2.0 and net10.0
  • Breaking: typed values (int, double, DateTime, …) are converted with the invariant culture, so -r=1.5 means 1.5 on every machine. Mono.Options used the current culture, where 1.5 fails on a machine with a decimal comma (lt-LT, de-DE, …)
  • Response files are closed when parsing fails part-way; previously the file handle stayed open until garbage collection
  • ArgumentSource.GetArgumentsFromFile opens the file on first enumeration, so an enumerable that is never enumerated does not leak a handle
  • A response file that includes itself, directly or indirectly, raises OptionException instead of recursing until resources run out (nesting limit: 64)
  • CommandSet.GetCompletions handles a prefix with leading whitespace correctly
  • The "Found {0} option values" error message is now passed to the message localizer before formatting, consistent with the other messages
  • Binary serialization members of OptionException are only compiled for netstandard2.0 (formatter-based serialization is obsolete on .NET 8+)
  • Tests ported from NUnit to xUnit v3

Building and testing

dotnet build
dotnet test

Requires the .NET 10 SDK.

License

MIT. See LICENSE. The original copyright notices are kept in the source file and in the license.

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 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.
  • .NETStandard 2.0

    • No dependencies.
  • net10.0

    • No dependencies.

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.9.0 229 10/22/2026