AlastairLundy.CliInvoke
2.0.0-rc.1
Prefix Reserved
dotnet add package AlastairLundy.CliInvoke --version 2.0.0-rc.1
NuGet\Install-Package AlastairLundy.CliInvoke -Version 2.0.0-rc.1
<PackageReference Include="AlastairLundy.CliInvoke" Version="2.0.0-rc.1" />
<PackageVersion Include="AlastairLundy.CliInvoke" Version="2.0.0-rc.1" />
<PackageReference Include="AlastairLundy.CliInvoke" />
paket add AlastairLundy.CliInvoke --version 2.0.0-rc.1
#r "nuget: AlastairLundy.CliInvoke, 2.0.0-rc.1"
#:package AlastairLundy.CliInvoke@2.0.0-rc.1
#addin nuget:?package=AlastairLundy.CliInvoke&version=2.0.0-rc.1&prerelease
#tool nuget:?package=AlastairLundy.CliInvoke&version=2.0.0-rc.1&prerelease
CliInvoke
<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.
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.
Why CliInvoke?
Feature | CliInvoke | CliWrap | ProcessX |
---|---|---|---|
Configure and Run External Processes using code written in .NET | ✅ | ✅ | ❌, Uses mixture of .NET and BASH syntax |
No Additional Licensing Terms Required for Use | ✅ | ❌ | ✅ |
Uses only managed .NET code | ✅ | ❌ | ✅ |
Follows Separation of Concerns and the Single Responsibility Principle | ✅ | ❌ | ❌ |
Allows for alternative Process Runners to be specified and/or used | ✅ | ❌ | ❌ |
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:
- For use in a .NET library - Install the Abstractions Package, your developer users can install the Implementation and Dependency Injection packages.
- For use in a .NET app - Install the Implementation Package and the Dependency Injection Extensions Package
Abstractions Package
dotnet add package AlastairLundy.CliInvoke.Core
Implementation Package
dotnet add package AlastairLundy.CliInvoke
Extensions Package
dotnet add package AlastairLundy.CliInvoke.Extensions
Specializations Package
CliInvoke.Specializations Nuget
dotnet add package AlastairLundy.CliInvoke.Specializations
Supported Platforms
CliInvoke can currently be added to .NET Standard 2.0, .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.
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 AlastairLundy.CliInvoke.Core.Factories;
using AlastairLundy.CliInvoke.Core;
using AlastairLundy.CliIinvoke;
using Microsoft.Extensions.DependencyInjection;
// Dependency Injection setup code ommitted for clarity
// Get IProcessConfigurationFactory
IProcessConfigurationFactory processConfigFactory = serviceProvider.GetRequiredService<IProcessConfigurationFactory>();
// Get IProcessConfigurationInvoker
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 StandardOutput and StandardError as strings.
using AlastairLundy.CliInvoke.Core.Factories;
using AlastairLundy.CliInvoke.Core;
using AlastairLundy.CliIinvoke;
using Microsoft.Extensions.DependencyInjection;
// Dependency Injection setup code ommitted for clarity
// Get IProcessConfigurationFactory
IProcessConfigurationFactory processConfigFactory = serviceProvider.GetRequiredService<IProcessConfigurationFactory>();
// Get IProcessConfigurationInvoker
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 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 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")
.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.Builders;
using AlastairLundy.CliInvoke.Core;
using AlastairLundy.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")
.WithArguments(["arg1", "arg2"])
.WithWorkingDirectory("/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);
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.
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-rc.1)
- AlastairLundy.DotExtensions (>= 9.0.0-preview.1)
-
net8.0
- AlastairLundy.CliInvoke.Core (>= 2.0.0-rc.1)
- AlastairLundy.DotExtensions (>= 9.0.0-preview.1)
-
net9.0
- AlastairLundy.CliInvoke.Core (>= 2.0.0-rc.1)
- AlastairLundy.DotExtensions (>= 9.0.0-preview.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on AlastairLundy.CliInvoke:
Package | Downloads |
---|---|
AlastairLundy.CliInvoke.Extensions
Adds a ``AddCliInvoke`` Dependency Injection extension method to enable easy CliInvoke setup when using the Microsoft.Extensions.DependencyInjection package. |
|
AlastairLundy.CliInvoke.Extensibility
Makes extending CliInvoke, and using custom Command Runners and Command Configurations easier. |
|
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-rc.1 | 29 | 10/19/2025 | |
2.0.0-beta.7 | 108 | 10/15/2025 | |
2.0.0-beta.6 | 124 | 10/14/2025 | |
2.0.0-beta.5 | 138 | 10/11/2025 | |
2.0.0-beta.4 | 108 | 10/9/2025 | |
2.0.0-beta.3 | 118 | 10/5/2025 | |
2.0.0-beta.2 | 166 | 10/1/2025 | |
2.0.0-beta.1 | 145 | 9/27/2025 | |
1.6.1.1 | 329 | 10/14/2025 | |
1.6.1 | 382 | 10/9/2025 | |
1.6.0 | 289 | 10/1/2025 | |
1.5.2 | 451 | 9/16/2025 | |
1.5.1 | 378 | 8/25/2025 | |
1.5.0 | 193 | 7/30/2025 | |
1.4.5 | 294 | 7/10/2025 | |
1.4.4 | 291 | 7/7/2025 | |
1.4.3 | 267 | 6/23/2025 | |
1.4.1 | 591 | 6/11/2025 | |
1.4.0 | 286 | 6/9/2025 | |
1.3.1 | 345 | 5/23/2025 | |
1.2.0 | 536 | 4/8/2025 | |
1.1.0 | 343 | 3/18/2025 | |
1.0.0 | 426 | 3/2/2025 |
## Changes since 2.0.0 Beta 7
* Update ``ProcessInvoker`` to allow specifying ``ProcessConfiguration`` disposal after invoker use
* Clarified OS support for ``IProcessResourcePolicyBuilder`` methods
* Updated DotExtensions from 8.6.2 to 9.0.0 Preview 1
* Updated EnvironmentVariablesBuilder to allow enabling/disabling exceptions if duplicate keys are attempted to be added.
* Renamed ``IEnvironmentVariablesBuilder`` methods to avoid ambiguous method usage
* Fixed potential no-op issues with ArgumentNullException in ``EnvironmentVariablesBuilder``