AlastairLundy.ProcessInvoke 1.5.0

Prefix Reserved
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package AlastairLundy.ProcessInvoke --version 1.5.0
                    
NuGet\Install-Package AlastairLundy.ProcessInvoke -Version 1.5.0
                    
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.ProcessInvoke" Version="1.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AlastairLundy.ProcessInvoke" Version="1.5.0" />
                    
Directory.Packages.props
<PackageReference Include="AlastairLundy.ProcessInvoke" />
                    
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.ProcessInvoke --version 1.5.0
                    
#r "nuget: AlastairLundy.ProcessInvoke, 1.5.0"
                    
#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.ProcessInvoke@1.5.0
                    
#: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.ProcessInvoke&version=1.5.0
                    
Install as a Cake Addin
#tool nuget:?package=AlastairLundy.ProcessInvoke&version=1.5.0
                    
Install as a Cake Tool

AlastairLundy.ProcessInvoke

In this readme, the package AlastairLundy.ProcessInvoke is referred to as ProcessInvoke for brevity.

ProcessInvoke adds much-needed abstractions and extensions to Processes and Process Running, to make it easier and safer.

ProcessInvoke started as part of CliInvoke but is now a separate package, helping other projects besides CliInvoke to run processes easily and safely.

NuGet NuGet

Table of Contents

Features

  • Easy to use and 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.

When should I use ProcessInvoke vs CliInvoke?

Use CliInvoke IF any of the following apply:

  • You want to programatically execute a Cli Application
  • You want to get the output of a Cli Application.
  • You want to Pipe the Input or Output of a Cli Application.

Use ProcessInvoke IF ALL the following apply:

  • You don't care about getting a Process's Standard Output.
  • You're focussed more on starting and/or stopping Processes.
  • You don't need Argument Building or Escaping capabilities

Note: Whilst ProcessInvoke is capable of doing most of what CliInvoke is capable of, they are intended for different use cases.

CliInvoke internally uses ProcessInvoke but provides additional abstractions around programatically executing programs and is designed specifically for this task.

How to install and use ProcessInvoke

ProcessInvoke is available on Nuget.

Installing ProcessInvoke

ProcessInvoke'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.ProcessInvoke AlastairLundy.ProcessInvoke Nuget dotnet add package AlastairLundy.ProcessInvoke

Supported Platforms

ProcessInvoke 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 ProcessInvoke is intended to be safe Process Running.

Safe Process Running

ProcessInvoke offers safe abstractions around Process Running to avoid accidentally not disposing of Processes after they are executed.

If directly executing the process and receiving a ProcessResult or BufferedProcessResult object is desirable you should use IProcessRunner as a service.

If you don't wish to immediately dispose of the Process after executing it, but plan to dispose of it later then IProcessRunnerUtility provides more flexibility.

IProcessRunner

Note: IProcessRunner and it's implementation class's execution methods do require a ProcessResultValidation argument to be passed, that configures whether validation should be performed on the Process' exit code. A default value for the parameter is intentionally not provided, as it is up to the user to decide whether they require exit code validation.

This example shows how it might be used:

using AlastairLundy.ProcessInvoke;
// Using namespaces for Dependency Injection code ommitted for clarity

//Namespace and classs code ommitted for clarity 

      // ServiceProvider and Dependency Injection code ommitted for clarity

    IProcessRunner _processRunner = serviceProvider.GetRequiredService<IProcessRunner>();
    

    ProcessResult result = await _processRunner.ExecuteProcessAsync(process, ProcessResultValidation.None);

Asynchronous methods in IProcessRunner do provide an optional CancellationToken parameter.

Synchronous methods are available in IProcessRunner but should be used as a last resort, in situations where using async and await are not possible.

IProcessRunnerUtility

The naming of IProcessRunnerUtility is deliberately similar to IProcessRunner as it is the utility interface (and corresponding implementing class) that IProcessRunner uses behind the scenes for functionality.

Usage of IProcessRunnerUtility is most appropriate when greater flexibility is required than what IProcessRunner provides.

For instance, you can keep a Process object alive for as long as needed, and then dispose of it later.

using AlastairLundy.ProcessInvoke;
using AlastairLundy.ProcessInvoke.Utilities.Abstractions;

// Using namespaces for Dependency Injection code ommitted for clarity

//Namespace and classs code ommitted for clarity 

      // ServiceProvider and Dependency Injection code ommitted for clarity

    IProcessRunnerUtility _processRunnerUtility = serviceProvider.GetRequiredService<IProcessRunnerUtility>();
    
    // Result Validation and Cancellation token are optional parameters.
    int exitCode = await _processRunnerUtility.ExecuteAsync(process);
    
    // Getting the result afterwards is done manually.
    ProcessResult = await _processRunnerUtility.GetResultAsync(process);
    
    // Code continuing to use process object ommitted.
    
    
    // Dispose of Process when no longer needed.
    _processRunnerUtility.DisposeOfProcess(process);

Some synchronous methods are available in IProcessRunnerUtility but should be used as a last resort, in situations where using async and await are not possible.

How to Build ProcessInvoke's code

Requirements

ProcessInvoke requires the latest .NET release SDK to be installed to target all supported TFM (Target Framework Moniker) build targets.

Currently, the required .NET SDK is .NET 9.

The current build targets include:

  • .NET 8
  • .NET 9
  • .NET Standard 2.0
  • .NET Standard 2.1

Any version of the .NET 9 SDK can be used, but using the latest version is preferred.

Versioning new releases

ProcessInvoke aims to follow Semantic versioning with [Major].[Minor].[Build] for most circumstances and an optional .[Revision] when only a configuration change is made, or a new build of a preview release is made.

Pre-releases

Pre-release versions should have a suffix of -alpha, -beta, -rc, or -preview followed by a . and what pre-release version number they are. The number should be incremented by 1 after each release unless it only contains a configuration change, or another packaging, or build change. An example pre-release version may look like 1.1.0-alpha.2; this version string would indicate it is the second alpha pre-release version of 1.1.0.

Stable Releases

Stable versions should follow semantic versioning and should only increment the Revision number if a release only contains configuration or build packaging changes, with no change in functionality, features, or even bug or security fixes.

Releases that only implement bug fixes should see the Build version incremented.

Releases that add new non-breaking changes should increment the Minor version. Minor breaking changes may be permitted in Minor version releases under some circumstances. These may include where doing so is necessary to maintain compatibility with an existing supported platform, or an existing piece of code that requires a breaking change to continue to function as intended.

Releases that add major breaking changes or significantly affect the API should increment the Major version. Major version releases should not be released with excessive frequency and should be released when there is a genuine need for the API to change significantly for the improvement of the project.

Building for Testing

You can build for testing by building the desired project within your IDE or VS Code, or manually by entering the following command: dotnet build -c Debug.

If you encounter any bugs or issues, please report them if an issue doesn't already exist for the bug(s).

Building for Release

Before building a release build, ensure you apply the relevant changes to AlastairLundy.ProcessInvoke.csproj file corresponding to the package you are trying to build:

  • Update the Package Version variable
  • Update the project file's Changelog

You should ensure the project builds under debug settings before producing a release build.

Producing Release Builds

To manually build a project for release, enter dotnet build -c Release /p:ContinuousIntegrationBuild=true for a release with SourceLink enabled or just dotnet build -c Release for a build without SourceLink.

Builds should generally always include Source Link and symbol packages if intended for wider distribution.

How to Contribute to ProcessInvoke

Thank you in advance for considering contributing to ProcessInvoke.

Please see the CONTRIBUTING.md file for code and localisation 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.

ProcessInvoke' Roadmap

ProcessInvoke aims to make working with processes easier and safer.

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 to focus on one or more of the following:

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

License

ProcessInvoke is licensed under the MPL 2.0 license. If you modify any of ProcessInvoke's files, then the modified files must be licensed under the MPL 2.0.

If you use ProcessInvoke in your project, please make an exact copy of the contents of ProcessInvoke'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:

  • Polyfill for simplifying .NET Standard 2.0 & 2.1 support
  • 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated

Initial release under new package name