AlastairLundy.CliInvoke.Core
1.3.0
Prefix Reserved
See the version list below for details.
dotnet add package AlastairLundy.CliInvoke.Core --version 1.3.0
NuGet\Install-Package AlastairLundy.CliInvoke.Core -Version 1.3.0
<PackageReference Include="AlastairLundy.CliInvoke.Core" Version="1.3.0" />
<PackageVersion Include="AlastairLundy.CliInvoke.Core" Version="1.3.0" />
<PackageReference Include="AlastairLundy.CliInvoke.Core" />
paket add AlastairLundy.CliInvoke.Core --version 1.3.0
#r "nuget: AlastairLundy.CliInvoke.Core, 1.3.0"
#addin nuget:?package=AlastairLundy.CliInvoke.Core&version=1.3.0
#tool nuget:?package=AlastairLundy.CliInvoke.Core&version=1.3.0
AlastairLundy.CliInvoke.Core
This package contains Process Running and handling abstractions as well as common types used by implementing classes.
For an implementing package, check out AlastairLundy.CliInvoke
.
Key Abstractions:
IProcessFactory
- Piping:
IProcessPipeHandler
- Builders:
IEnvironmentVariablesBuilder
IProcessResourcePolicyBuilder
IUserCredentialBuilder
Some primitives added include:
Result Types
ProcessResult
- For basic process result informationBufferedProcessResult
- String copies of Standard Output and Standard Error + basic process result information.PipedProcessResult
- Process result information + Standard output and Standard Error pipes for more advanced piping scenarios.
Other Primitives
ProcessResultValidation
- An enum representing whether process result validation should be performed or not.ProcessConfiguration
- A model class for representing Process configurations.
Table of Contents
Features
- Easy to use safe Process Running classes and interfaces
- Models that help abstract away some of the complicated nature of Process objects
- Compatible with .NET Standard 2.0 and 2.1 ^1
- SourceLink support
^1 - Polyfill is a dependency only required for .NET Standard 2.0 and 2.1 users. Microsoft.Bcl.HashCode is a dependency only required for .NET Standard 2.0 users.
How to install and use CliInvoke.Core
CliInvoke.Core is available on Nuget.
Installing CliInvoke.Core
CliInvoke.Core 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.Core | AlastairLundy.CliInvoke.Core Nuget | dotnet add package AlastairLundy.CliInvoke.Core |
Supported Platforms
CliInvoke.Core can be added to any .NET Standard 2.0, .NET Standard 2.1, .NET 8, or .NET 9 supported project.
The following table details which target platforms are supported for running Processes.
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. ^2 |
tvOS | Not Supported ❌ | Not supported due to Process.Start() not supporting tvOS ^2 |
watchOS | Not Supported ❌ | Not supported due to Process.Start() not supporting watchOS ^3 |
Browser | Not Supported and Not Planned ❌ | Not supported due to not being a valid target Platform for executing processes. |
^2 - See the Process class documentation for more info.
^3 - lack of IOS support implies Lack of watchOS support since watchOS is based on IOS.
Note: This library has not been tested on Android or Tizen.
Examples
One of the main use cases for CliInvoke.Core is intended to be safe Process Running.
Safe Process Running
CliInvoke.Core offers safe abstractions around Process Running to avoid accidentally not disposing of Processes after they are executed.
IProcessFactory
provides for this in
IProcessFactory
IProcessFactory is an interface for enabling easy Process Creation, Running, and Disposal depending on the methods used.
The From
method and its overloads provide for easy standalone process creation.
The StartNew
method provides for creating and starting new processes easily.
The ContinueWhenExitAsync
and ContinueWhenExitBufferedAsync
methods provide for safe process running, and disposal after a Process has exited.
This example shows how it might be used:
using AlastairLundy.CliInvoke.Core;
// Using namespaces for Dependency Injection code ommitted for clarity
// Dependency Injection setup code ommitted for clarity
IProcessFactory _processFactory = serviceProvider.GetRequiredService<IProcessFactory>();
// Define processStartInfo here.
Process process1 = _processFactory.From(processStartInfo);
// This process that is returned is a Process that has been started.
Process process2 = _processFactory.StartNew(processStartInfo);
// Wait for the Process to finish before safely disposing of it.
ProcessResult result = await processFactory.ContinueWhenExitAsync(process2);
ProcessResult result = await _processRunner.ExecuteProcessAsync(process, ProcessResultValidation.None);
Asynchronous methods in IProcessFactory
also allow for an optional CancellationToken parameter.
Some overloads for ContinueWhenExitAsync
and ContinueWhenExitBufferedAsync
allow for specifying ProcessResultValidation.
How to Contribute
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.
License
CliInvoke.Core is licensed under the MPL 2.0 license. If you modify any of CliInvoke.Core's files, then the modified files must be licensed under the MPL 2.0.
If you use CliInvoke.Core in your project, please make an exact copy of the contents of CliInvoke.Core' 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:
- Microsoft.Bcl.HashCode for providing a backport of the HashCode class and static methods to .NET Standard 2.0
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 is compatible. |
.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.DotExtensions (>= 6.6.0)
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Polyfill (>= 7.27.0)
- System.IO.Pipelines (>= 9.0.4)
-
.NETStandard 2.1
- AlastairLundy.DotExtensions (>= 6.6.0)
- Polyfill (>= 7.27.0)
- System.IO.Pipelines (>= 9.0.4)
-
net8.0
- AlastairLundy.DotExtensions (>= 6.6.0)
- System.IO.Pipelines (>= 9.0.4)
-
net9.0
- AlastairLundy.DotExtensions (>= 6.6.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on AlastairLundy.CliInvoke.Core:
Package | Downloads |
---|---|
AlastairLundy.CliInvoke
CliInvoke is a .NET Library for interacting with Command Line Interfaces, CliInvoke is a library for interacting with Command Line Interfaces and wrapping around executables. |
|
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. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Moved abstractions code to this library and merged with ProcessInvoke Primitives and ProcessInvoke Abstractions