CliInvoke 2.1.2

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

CliInvoke

Latest NuGet Latest Pre-release NuGet Downloads License

<img src="https://github.com/alastairlundy/CliInvoke/blob/main/.assets/icon.png" width="192" height="192" alt="CliInvoke Logo">

CliInvoke is a .NET library for interacting with Command Line Interfaces and wrapping around executables.

Launch processes, redirect standard input and output streams, await process completion and much more.

Table of Contents

Features

  • Clear separation of concerns between Process Configuration Builders, Process Configuration Models, and Invokers.
  • Supports .NET Standard 2.0, .NET 8 and newer TFMs, and has few dependencies.
  • Has Dependency Injection extensions to make using it a breeze.
  • Support for specific specializations such as running executables or commands via Windows PowerShell or CMD on Windows <sup>1</sup>
  • SourceLink support

<sup>1</sup> Specializations library distributed separately.

Comparison vs Alternatives

Feature / Criterion CliInvoke CliWrap ProcessX
Dedicated builder, model, and invoker types (clear separation of concerns)
Dependency Injection registration extensions
Installable via NuGet
Official cross‑platform support (advertised: Windows/macOS/Linux/BSD) ✅* ❌*
Buffered and non‑buffered execution modes
Small surface area and minimal dependencies
Licensing / repository additional terms ✅ (MPL‑2.0) ⚠️ (MIT; test project references a source‑available library; repo contains an informal "Terms of Use" statement) ✅ (MIT)

Notes:

  • *Indicates not explicitly advertised for all listed OSes but may work in practice; check each project's docs.
  • The CliWrap repository includes a test project that references a source‑available (non‑permissive) library; that library is used for tests and is not distributed with the runtime package. The repo also contains an informal "Terms of Use" statement — review repository files if legal certainty is required.

Installing CliInvoke

CliInvoke is available on the NuGet Gallery but call be also installed via the dotnet SDK CLI.

The package(s) to install depends on your use case:

Project type / Need Packages to install (dotnet add package ...) Notes
Library author (provide abstractions only) CliInvoke.Core Only the Core (abstractions) package — consumers can choose implementations.
Library or app that needs concrete builders / implementations CliInvoke.Core, CliInvoke Implementation package plus Core for models/abstractions.
Desktop or Console application (common case — use DI & convenience helpers) CliInvoke.Core, CliInvoke, CliInvoke.Extensions Includes DI registration and convenience extensions for easy setup.
Any project that needs platform‑specific or shell specializations (optional) CliInvoke.Specializations (install in addition to the packages above as needed) Adds Cmd/PowerShell and other specializations; include only when required.

CliInvoke.Core Nuget CliInvoke Nuget CliInvoke.Extensions Nuget CliInvoke.Specializations Nuget

Supported Platforms

CliInvoke supports Windows, macOS, Linux, FreeBSD, Android, and potentially some other operating systems.

For more details see the list of supported platforms

Getting started

Install the packages you need (example: implementation + DI extensions):

dotnet add package CliInvoke
dotnet add package CliInvoke.Extensions

Minimal Program.cs (console app) — registers services, builds a simple process configuration, and runs it buffered:

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using CliInvoke;
using CliInvoke.Core;
using CliInvoke.Core.Factories;

class Program
{
    static async Task Main()
    {
        var services = new ServiceCollection();
        services.AddCliInvoke(); // from CliInvoke.Extensions
        var provider = services.BuildServiceProvider();

        var factory = provider.GetRequiredService<IProcessConfigurationFactory>();
        var invoker = provider.GetRequiredService<IProcessConfigurationInvoker>();

        // Create a simple configuration (adjust path/args for your OS)
        var config = factory.Create("dotnet", "--info");

        // Run and get buffered output
        BufferedProcessResult result = await invoker.ExecuteBufferedAsync(config, CancellationToken.None);

        Console.WriteLine($"ExitCode: {result.ExitCode}");
        Console.WriteLine("Stdout:");
        Console.WriteLine(result.StandardOutput);
        Console.WriteLine("Stderr:");
        Console.WriteLine(result.StandardError);
    }
}

Notes

  • Replace "dotnet --info" with the executable and arguments you need for your platform.
  • For non‑buffered/streaming scenarios, use ExecuteAsync/ExecuteBufferedAsync variants and builder options to redirect streams instead of buffering everything in memory.

Examples

Simple ProcessConfiguration creation with Factory Pattern

This approach uses the IProcessConfigurationFactory interface factory to create a ProcessConfiguration. It requires fewer parameters and sets up more defaults for you.

It can be provided with a Action<IProcessConfigurationBuilder> configure optional parameter where greater control is desired.

Non-Buffered Execution Example

This example gets a non buffered ProcessResult that contains basic process exit code, Id, and other information.

using CliInvoke.Core.Factories;
using CliInvoke.Core;
using AlastairLundy.CliIinvoke;

using Microsoft.Extensions.DependencyInjection;

// Dependency Injection setup code omitted for clarity

// Get services 
IProcessConfigurationFactory processConfigFactory = serviceProvider.GetRequiredService<IProcessConfigurationFactory>();
IProcessConfigurationInvoker _invoker_ = serviceProvider.GetRequiredService<IProcessConfigurationInvoker>();

// Simply create the process configuration.
ProcessConfiguration configuration = processConfigFactory.Create("path/to/exe", "arguments");

// Run the process configuration and get the results.
ProcessResult result = await _invoker.ExecuteAsync(configuration, CancellationToken.None);
Buffered Execution Example

This example gets a BufferedProcessResult which contains redirected Standard Output and Standard Error as strings.

using CliInvoke.Core.Factories;
using CliInvoke.Core;

using Microsoft.Extensions.DependencyInjection;

// Dependency Injection setup code omitted for clarity

// Get services 
IProcessConfigurationFactory processConfigFactory = serviceProvider.GetRequiredService<IProcessConfigurationFactory>();
IProcessConfigurationInvoker _invoker_ = serviceProvider.GetRequiredService<IProcessConfigurationInvoker>();

// Simply create the process configuration.
ProcessConfiguration configuration = processConfigFactory.Create("path/to/exe", "arguments");

// Run the process configuration and get the results.
BufferedProcessResult result = await _invoker.ExecuteBufferedAsync(configuration, CancellationToken.None);

Advanced Configuration with Builders

The following examples show how to configure and build a ProcessConfiguration depending on whether Buffering the output is desired.

Non-Buffered Execution Example

This example gets a non buffered ProcessResult that contains basic process exit code, id, and other information.

using CliInvoke;
using CliInvoke.Core;

using CliInvoke.Builders;
using CliInvoke.Core.Builders;

using Microsoft.Extensions.DependencyInjection;

  //Namespace and class code ommitted for clarity 

  // ServiceProvider and Dependency Injection setup code oomittedfor clarity
  
  IProcessInvoker _processInvoker = serviceProvider.GetRequiredService<IProcessInvoker>();

  // Fluently configure your Command.
  IProcessConfigurationBuilder builder = new ProcessConfigurationBuilder("Path/To/Executable")
                            .SetArguments(["arg1", "arg2"])
                            .SetWorkingDirectory("/Path/To/Directory");
  
  // Build it as a ProcessConfiguration object when you're ready to use it.
  ProcessConfiguration config = builder.Build();
  
  // Execute the process through ProcessInvoker and get the results.
ProcessResult result = await _processConfigInvoker.ExecuteAsync(config);
Buffered Execution Example

This example gets a BufferedProcessResult which contains redirected StandardOutput and StandardError as strings.

using CliInvoke;
using CliInvoke.Builders;

using CliInvoke.Core;
using CliInvoke.Core.Builders;

using Microsoft.Extensions.DependencyInjection;


  //Namespace and class code ommitted for clarity 

  // ServiceProvider and Dependency Injection setup code ommitted for clarity
  
  IProcessInvoker _processInvoker = serviceProvider.GetRequiredService<IProcessInvoker>();

  // Fluently configure your Command.
  IProcessConfigurationBuilder builder = new ProcessConfigurationBuilder("Path/To/Executable")
                            .SetArguments(["arg1", "arg2"])
                            .SetWorkingDirectory("/Path/To/Directory")
                            .RedirectStandardOutput(true)
                           .RedirectStandardError(true);
  
  // Build it as a ProcessConfiguration object when you're ready to use it.
  ProcessConfiguration config = builder.Build();
  
  // Execute the process through ProcessInvoker and get the results.
BufferedProcessResult result = await _processInvoker.ExecuteBufferedAsync(config);

How to Build CliInvoke's code

Please see building-cliinvoke.md for how to build CliInvoke from source.

How to Contribute to CliInvoke

Please see the CONTRIBUTING.md file for code and localization contributions.

If you want to file a bug report or suggest a potential feature to add, please check out the GitHub issues page to see if a similar or identical issue is already open. If there isn't already a relevant issue filed, please file one here and follow the respective guidance from the appropriate issue template.

Used By

CliInvoke is used by these projects:

Want your project added to this list? Open an issue

CliInvoke's Roadmap

CliInvoke aims to make working with Commands and external processes easier.

Whilst an initial set of features are available in version 1, there is room for more features, and for modifications of existing features in future updates.

Future updates may focus on one or more of the following:

  • Improved ease of use
  • Improved stability
  • New features
  • Enhancing existing features

License

CliInvoke is licensed under the MPL 2.0 license. You can learn more about it here

If you use CliInvoke in your project please make an exact copy of the contents of CliInvoke's LICENSE.txt file available either in your third party licenses TXT file or as a separate TXT file in the project's repository.

CliInvoke Assets

CliInvoke's Icon is proprietary with all rights reserved to me (Alastair Lundy).

If you fork CliInvoke and re-distribute it, please replace the usage of the icon unless you have prior written approval from me.

Acknowledgements

Projects

This project would like to thank the following projects for their work:

  • CliWrap for inspiring this project
  • Polyfill for simplifying .NET Standard 2.0 support

For more information, please see the THIRD_PARTY_NOTICES file.

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

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CliInvoke:

Package Downloads
CliInvoke.Extensions

Adds a ``AddCliInvoke`` Dependency Injection extension method to enable easy CliInvoke setup when using the Microsoft.Extensions.DependencyInjection package.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.0-alpha.2 353 12/11/2025
2.2.0-alpha.1 615 12/1/2025
2.1.2 416 12/11/2025
2.1.1 511 11/18/2025
2.1.0 213 11/15/2025
2.0.1 432 11/18/2025
2.0.0 260 11/14/2025

* Updated to internal Polyfill version 9.3.4 from 9.1.0