CliInvoke.Specializations 3.0.0

Prefix Reserved
dotnet add package CliInvoke.Specializations --version 3.0.0
                    
NuGet\Install-Package CliInvoke.Specializations -Version 3.0.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="CliInvoke.Specializations" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CliInvoke.Specializations" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CliInvoke.Specializations" />
                    
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 CliInvoke.Specializations --version 3.0.0
                    
#r "nuget: CliInvoke.Specializations, 3.0.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 CliInvoke.Specializations@3.0.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=CliInvoke.Specializations&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CliInvoke.Specializations&version=3.0.0
                    
Install as a Cake Tool

CliInvoke.Specializations

This readme covers the CliInvoke Specializations library.

Looking for the CliInvoke Readme?

Latest NuGet Latest Pre-release NuGet Downloads License

Usage

CliInvoke.Specializations ships two specializations:

  • CmdProcessConfiguration — An easier way to execute processes and commands through Windows' cmd.exe.
  • PowershellProcessConfiguration — An easier way to execute processes and commands through the modern Cross-Platform open source PowerShell (PowerShell is not installed by CliInvoke and is expected to be installed if you plan to use it.)

All Command specialization classes come with an already configured TargetFilePath that points to the relevant executable.

Quick start with CliRun

The fastest path is the static CliRun helper. Build a configuration and await the result.

using CliInvoke;
using CliInvoke.Core;
using CliInvoke.Specializations.Configurations;

// Run a PowerShell command using the cross-platform pwsh executable.
using PowershellProcessConfiguration config = new PowershellProcessConfiguration("-Command Get-Process");

BufferedProcessResult result = await CliRun.RunBufferedAsync(config, ProcessExitConfiguration.CreateGraceful());


CliRun also exposes RunAsync (returns a ProcessResult) and FireAndForget for fire-and-forget execution.

Dependency Injection

If you prefer to resolve an invoker from a dependency injection container, call AddCliInvoke() (namespace CliInvoke.Extensions, shipped in the main CliInvoke package). This registers the core services, the IProcessInvoker implementation, the IRunnerConfigurationFactory, and the IExternalProcessFactory.

AddCliInvokeSpecializations

AddCliInvokeSpecializations() (namespace CliInvoke.Extensions, shipped in this package) registers the Specializations middleware types — PowerShellMiddleware, CmdMiddleware, DefaultShellMiddleware, and ShellMiddlewareOptions — so that the convenience builder extensions UsePowerShell(), UseCmd(), and UseDefaultShell() can resolve them from the DI container.

DefaultShellMiddleware detects the user's default shell (pwsh, Windows PowerShell, or cmd) and wraps the command in it automatically. Use it when you want cross-platform shell detection instead of targeting a specific shell.

AddCliInvoke() is required. AddCliInvokeSpecializations() only registers middleware types; it does not register core CliInvoke services. You must call AddCliInvoke() as well, or the invoker, process factory, and other core services will not be available.

Both registrations accept an optional ServiceLifetime parameter (default Scoped). The two calls are independent and can be chained in either order, but both must use the same lifetime — middleware lifetimes are matched to the invoker lifetime to avoid capturing scoped services into a singleton:

using CliInvoke.Extensions;
using Microsoft.Extensions.DependencyInjection;

ServiceCollection services = new ServiceCollection();

// AddCliInvoke() is required — it registers core services.
// AddCliInvokeSpecializations() registers the Cmd/PowerShell/DefaultShell middleware types.
services.AddCliInvoke(builder => builder.UsePowerShell().UseCmd())
    .AddCliInvokeSpecializations();

using IServiceProvider serviceProvider = services.BuildServiceProvider();

Calling AddCliInvoke(builder => builder.UsePowerShell()) without AddCliInvokeSpecializations() compiles but throws InvalidOperationException when the invoker is first resolved, because the PowerShellMiddleware type is not registered in the container.

CmdProcessConfiguration

The CmdProcessConfiguration TargetFilePath points to Windows' copy of cmd.exe. This is only supported on Windows.

using CliInvoke;
using CliInvoke.Core;
using CliInvoke.Core.Extensibility;
using CliInvoke.Specializations.Configurations;

    // DI setup omitted for clarity

IProcessInvoker _processInvoker = serviceProvider.GetRequiredService<IProcessInvoker>();
IRunnerConfigurationFactory _runnerConfigurationFactory = serviceProvider.GetRequiredService<IRunnerConfigurationFactory>();

ProcessConfiguration runnerConfig = new CmdProcessConfiguration("Your arguments go here",
    false, true, Environment.SystemDirectory);

ProcessConfiguration config = new ProcessConfiguration("Path/To/Exe", "With/Arguments");
ProcessConfiguration processToRun = _runnerConfigurationFactory.CreateRunnerConfiguration(config, runnerConfig);

BufferedProcessResult result = await _processInvoker.ExecuteBufferedAsync(processToRun);

To discard the output, call ExecuteAsync() instead:

// Same setup as above, then:
ProcessResult result = await _processInvoker.ExecuteAsync(processToRun);

PowershellProcessConfiguration

PowershellProcessConfiguration.TargetFilePath points to the installed copy of cross-platform PowerShell. Supported on the platforms that pwsh supports.

using CliInvoke;
using CliInvoke.Core;
using CliInvoke.Core.Extensibility;
using CliInvoke.Specializations.Configurations;

// DI setup omitted for clarity

IProcessInvoker _processInvoker = serviceProvider.GetRequiredService<IProcessInvoker>();
IRunnerConfigurationFactory _runnerConfigurationFactory = serviceProvider.GetRequiredService<IRunnerConfigurationFactory>();

ProcessConfiguration runnerConfig = new PowershellProcessConfiguration("-Command Get-Process",
    false, true);

ProcessConfiguration config = new ProcessConfiguration("Path/To/Exe", "With/Arguments");
ProcessConfiguration processToRun = _runnerConfigurationFactory.CreateRunnerConfiguration(config, runnerConfig);

BufferedProcessResult result = await _processInvoker.ExecuteBufferedAsync(processToRun);

Dedicated invokers

CliInvoke.Specializations also ships two convenience invoker wrappers — CmdProcessInvoker and PowershellProcessInvoker (namespace CliInvoke.Specializations) — that implement IProcessInvoker with the relevant middleware (CmdMiddleware / PowerShellMiddleware) applied. They run commands through cmd.exe / pwsh directly without manually building a runner configuration.

Both are constructed from an IExternalProcessFactory, which AddCliInvoke() (main CliInvoke package) registers in the container:

using CliInvoke.Core;
using CliInvoke.Core.Factories;
using CliInvoke.Specializations;
using CliInvoke.Specializations.Configurations;

// Resolve the external process factory registered by AddCliInvoke().
IExternalProcessFactory factory = serviceProvider.GetRequiredService<IExternalProcessFactory>();

// CmdProcessInvoker applies CmdMiddleware and runs through cmd.exe (Windows only).
using CmdProcessInvoker cmdInvoker = new CmdProcessInvoker(factory);

using CmdProcessConfiguration cmdConfig = new CmdProcessConfiguration("echo hello", false, true);
ProcessResult result = await cmdInvoker.ExecuteAsync(cmdConfig);

PowershellProcessInvoker works the same way and is supported on the platforms that cross-platform PowerShell supports.

Licensing

CliInvoke and CliInvoke Specializations are licensed under the MPL 2.0 license.

If you use CliInvoke or CliInvoke.Specializations in your project, please make an exact copy of CliInvoke's LICENSE.txt file available either in your third party licenses txt file or as a separate txt file.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
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
3.0.0 36 9/13/2026
2.11.2 36 9/13/2026
2.11.1 44 9/10/2026
2.11.0 94 9/2/2026
2.10.7 50 9/13/2026
2.10.6 46 9/10/2026
2.10.5 90 8/30/2026
2.10.4 97 8/26/2026
2.10.3 104 8/19/2026
2.9.4 87 8/30/2026
2.9.2 95 8/19/2026
2.8.5 89 8/30/2026
Loading failed

AddCliInvokeSpecializations is the registration entry point (must chain with AddCliInvoke, same ServiceLifetime)
PowerShellMiddleware, CmdMiddleware, DefaultShellMiddleware and their UsePowerShell/UseCmd/UseDefaultShell extensions
ShellMiddlewareOptions (renamed from PowerShellMiddlewareOptions)
ShellArgumentEscaper.EscapeForPosixShell for POSIX shell escaping
ShellArgumentEscaper relocated here with hardened escaping
IFilePathResolver removed from PowershellProcessConfiguration, PowershellProcessInvoker, and PowerShellMiddleware constructors
CmdProcessInvoker and PowershellProcessInvoker wrapper types deleted. Use middleware instead.
Specialized invokers refactored into thin wrappers over ProcessInvoker + middleware