AlastairLundy.CliInvoke
2.0.0-beta.4
Prefix Reserved
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
<PackageReference Include="AlastairLundy.CliInvoke" Version="2.0.0-beta.4" />
<PackageVersion Include="AlastairLundy.CliInvoke" Version="2.0.0-beta.4" />
<PackageReference Include="AlastairLundy.CliInvoke" />
paket add AlastairLundy.CliInvoke --version 2.0.0-beta.4
#r "nuget: AlastairLundy.CliInvoke, 2.0.0-beta.4"
#:package AlastairLundy.CliInvoke@2.0.0-beta.4
#addin nuget:?package=AlastairLundy.CliInvoke&version=2.0.0-beta.4&prerelease
#tool nuget:?package=AlastairLundy.CliInvoke&version=2.0.0-beta.4&prerelease
CliInvoke
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
- Why CliInvoke?
- Installing CliInvoke
- CliInvoke Examples
- Contributing to CliInvoke
- Roadmap
- License
- Acknowledgements
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:
- CliInvoke - The main CliInvoke package.
- CliInvoke.Extensions
- CliInvoke.Specializations
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:
- executing Programs/Commands programatically which involves using abstractions to improve the experience of external Program/Command running.
- safe Process Running which involves avoiding the pitfalls of the
Process
class whilst still dealing withProcessStartInfo
.
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:
For more information, please see the THIRD_PARTY_NOTICES file.
Product | Versions 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. |
-
.NETStandard 2.0
- AlastairLundy.CliInvoke.Core (>= 2.0.0-beta.4)
- AlastairLundy.DotExtensions (>= 8.6.2)
-
net8.0
- AlastairLundy.CliInvoke.Core (>= 2.0.0-beta.4)
- AlastairLundy.DotExtensions (>= 8.6.2)
-
net9.0
- AlastairLundy.CliInvoke.Core (>= 2.0.0-beta.4)
- AlastairLundy.DotExtensions (>= 8.6.2)
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