AlastairLundy.CliInvoke 2.0.0-beta.4

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

CliInvoke

NuGet NuGet

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 so much more.

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

Table of Contents

Features

  • Promotes the single responsibility principle and separation of concerns
  • Supports .NET Standard 2.0, .NET 8 and newer TFMs, and has few dependencies.
  • Dependency Injection extensions to make using CliInvoke 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> - The Specialization library is distributed separately here.

Why use CliInvoke over CliWrap?

  • Greater separation of concerns - Command Building, Command Running, and Command Pipe handling are moved to separate classes.
  • Supports and was designed with Dependency Injection in mind
  • Classes and code follow the Single Responsibility Principle
  • No additional licensing terms are required beyond the source code license.
  • No imported C code - This library is entirely written in C#.
  • No lock in regarding Piping support
  • Supports .NET's built in ProcessStartInfo primitive.

How to install and use CliInvoke

CliInvoke is available on Nuget.

These are the CliInvoke projects:

Installing CliInvoke

CliInvoke's packages can be installed via the .NET SDK CLI, Nuget via your IDE or code editor's package interface, or via the Nuget website.

Package Name Nuget Link .NET SDK CLI command
AlastairLundy.CliInvoke CliInvoke Nuget dotnet add package AlastairLundy.CliInvoke
AlastairLundy.CliInvoke.Extensions AlastairLundy.CliInvoke.Extensions Nuget dotnet add package AlastairLundy.CliInvoke.Extensions
AlastairLundy.CliInvoke.Specializations AlastairLundy.CliInvoke.Specializations Nuget dotnet add package AlastairLundy.CliInvoke.Specializations

Supported Platforms

CliInvoke can currently be added to .NET 8, or .NET 9 or newer supported projects.

The following table details which target platforms are supported for executing commands via CliInvoke.

Operating System Support Status Notes
Windows Fully Supported ✅
macOS Fully Supported ✅
Mac Catalyst Untested Platform ⚠️ Support for this platform has not been tested but should theoretically work.
Linux Fully Supported ✅
FreeBSD Fully Supported ✅
Android Untested Platform ⚠️ Support for this platform has not been tested but should theoretically work.
IOS Not Supported ❌ Not supported due to Process.Start() not supporting IOS. <sup>3</sup>
tvOS Not Supported ❌ Not supported due to Process.Start() not supporting tvOS <sup>3</sup>
watchOS Not Supported ❌ Not supported due to Process.Start() not supporting watchOS <sup>4</sup>
Browser Not Planned ❌ Not supported due to not being a valid target Platform for executing programs or processes.

<sup>3</sup> - See the Process class documentation for more info.

<sup>4</sup> - Lack of watchOS support is implied by lack of IOS support since watchOS is based on IOS.

Note: This library has not been tested on Android or Tizen.

Using CliInvoke / Examples

The two main use cases for CliInvoke are intended to be:

  1. executing Programs/Commands programatically which involves using abstractions to improve the experience of external Program/Command running.
  2. safe Process Running which involves avoiding the pitfalls of the Process class whilst still dealing with ProcessStartInfo.

CliInvoke provides both options to give developers a choice in the approach they adopt. They are both equally safe and valid.

Approaches

Safe Process Running

CliInvoke offers safe abstractions around Process Running to avoid accidentally not disposing of Processes, along with avoiding other pitfalls.

Running Programs/Commands

Because of how much of a minefield the Process class is and how difficult it can be to configure correctly, CliInvoke provides some abstractions to make it easier to configure Programs/Commands to be run.

CliInvoke provides fluent builder interfaces and implementing classes to easily configure ProcessConfiguration. ProcessConfiguration is CliInvoke's main form of Process configuration (hence the name).

Approach Examples

IProcessConfigurationInvoker

The following examples shows 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 AlastairLundy.CliInvoke;
using AlastairLundy.CliInvoke.Core;

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

using AlastairLundy.CliInvoke.Core.Primitives;

  //Namespace and class code ommitted for clarity 

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

  // Fluently configure your Command.
  IProcessConfigurationBuilder builder = new ProcessConfigurationBuilder("Path/To/Executable")
                            .WithArguments(["arg1", "arg2"])
                            .WithWorkingDirectory("/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 AlastairLundy.CliInvoke;
using AlastairLundy.CliInvoke.Core;

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

using AlastairLundy.CliInvoke.Core.Primitives;

  //Namespace and class code ommitted for clarity 

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

  // Fluently configure your Command.
  IProcessConfigurationBuilder builder = new ProcessConfigurationBuilder("Path/To/Executable")
                            .WithArguments(["arg1", "arg2"])
                            .WithWorkingDirectory("/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.
BufferedProcessResult result = await _processConfigInvoker.ExecuteBufferedAsync(config);

How to Build CliInvoke's code

How to Contribute to CliInvoke

Thank you in advance for considering contributing 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 is not already a relevant issue filed, please file one here and follow the respective guidance from the appropriate issue template.

Thanks.

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.

That being said, all stable releases from 1.0 onwards must be stable and should not contain regressions.

Future updates should aim 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. If you modify any of CliInvoke's files then the modified files must be licensed under the MPL 2.0 .

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.

CliInvoke Assets

CliInvoke's Icon is NOT licensed under the MPL 2.0 license and is licensed under Copyright 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 agreements 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 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 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 (3)

Showing the top 3 NuGet packages that depend on AlastairLundy.CliInvoke:

Package Downloads
AlastairLundy.CliInvoke.Extensibility

Makes extending CliInvoke, and using custom Command Runners and Command Configurations easier.

AlastairLundy.CliInvoke.Extensions

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

AlastairLundy.WCountLib.Providers.wc

This package provides implementations for WCountLib.Abstractions interfaces that use Posix's and Unix's ``wc`` program to perform the calculations.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-beta.5 83 10/11/2025
2.0.0-beta.4 103 10/9/2025
2.0.0-beta.3 116 10/5/2025
2.0.0-beta.2 162 10/1/2025
2.0.0-beta.1 142 9/27/2025
1.6.1 154 10/9/2025
1.6.0 286 10/1/2025
1.5.2 450 9/16/2025
1.5.1 357 8/25/2025
1.5.0 190 7/30/2025
1.4.5 291 7/10/2025
1.4.4 279 7/7/2025
1.4.3 266 6/23/2025
1.4.1 588 6/11/2025
1.4.0 274 6/9/2025
1.3.1 338 5/23/2025
1.2.0 533 4/8/2025
1.1.0 342 3/18/2025
1.0.0 422 3/2/2025

### Changes since 2.0.0 Beta 3
* Re-added .NET Standard 2.0 support

### Improvements
* Fixed an issue where an invalid Process Timeout Threshold could be provided via ``ProcessTimeoutPolicyBuilder``'s ``WithTimeoutThreshold`` method - This now results in an ``ArgumentOutOfRangeException`` being thrown.
* Updated Forceful Cancellation to now terminate the process and it's child processes.
* Updated ``PipedProcessResult`` to implement ``IDisposable`` and dispose of the Stream parameters when Dispose or DisposeAsync is called
* (Main package only) Moved Process extensions from DotExtensions into CliInvoke main package - These are now internal
* Changed default value for ``ProcessResourcePolicy``'s ``PriorityBoostEnabled`` value from ``true`` to ``false``
* Updated builder interfaces