CliInvoke.Specializations 3.0.1

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package CliInvoke.Specializations --version 3.0.1
                    
NuGet\Install-Package CliInvoke.Specializations -Version 3.0.1
                    
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.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CliInvoke.Specializations" Version="3.0.1" />
                    
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.1
                    
#r "nuget: CliInvoke.Specializations, 3.0.1"
                    
#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.1
                    
#: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.1
                    
Install as a Cake Addin
#tool nuget:?package=CliInvoke.Specializations&version=3.0.1
                    
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 three shell middleware types: PowerShellMiddleware (UsePowerShell()), CmdMiddleware (UseCmd()), and DefaultShellMiddleware (UseDefaultShell()). They wrap the command in the relevant shell at invocation time.

The legacy CmdProcessConfiguration and PowershellProcessConfiguration subclasses are deprecated, marked [Obsolete], and will be removed in 4.0. New code should use ProcessConfiguration with the matching middleware instead. The old subclasses are still documented below for existing users:

Quick start with CliRun

The fastest path is the static CliRun helper. CliRun runs each call through a fresh pipeline with no middleware, so target the shell executable directly.

using CliInvoke;
using CliInvoke.Core;

// Run a PowerShell command using the cross-platform pwsh executable.
ProcessConfiguration config = new ProcessConfiguration
{
    TargetFilePath = "pwsh",
    Arguments = "-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. To wrap commands through middleware instead, use the dependency injection path below.

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 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 ServiceProvider 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 (deprecated)

CmdProcessConfiguration is marked [Obsolete] and will be removed in 4.0. New code should use ProcessConfiguration with UseCmd() middleware. The example below remains for existing users.

using CliInvoke.Core;
using CliInvoke.Extensions;
using CliInvoke.Specializations.Middleware;
using Microsoft.Extensions.DependencyInjection;

ServiceCollection services = new ServiceCollection();

services.AddCliInvoke(builder => builder.UseCmd())
    .AddCliInvokeSpecializations();

using ServiceProvider serviceProvider = services.BuildServiceProvider();

IProcessInvoker processInvoker = serviceProvider.GetRequiredService<IProcessInvoker>();

ProcessConfiguration config = new ProcessConfiguration
{
    TargetFilePath = "Path/To/Exe",
    Arguments = "With/Arguments"
};

BufferedProcessResult result = await processInvoker.ExecuteBufferedAsync(config);

The legacy subclass equivalent, for existing users only: 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 (deprecated)

PowershellProcessConfiguration is marked [Obsolete] and will be removed in 4.0. New code should use ProcessConfiguration with UsePowerShell() middleware. The example below remains for existing users.

using CliInvoke.Core;
using CliInvoke.Extensions;
using CliInvoke.Specializations.Middleware;
using Microsoft.Extensions.DependencyInjection;

ServiceCollection services = new ServiceCollection();

services.AddCliInvoke(builder => builder.UsePowerShell())
    .AddCliInvokeSpecializations();

using ServiceProvider serviceProvider = services.BuildServiceProvider();

IProcessInvoker processInvoker = serviceProvider.GetRequiredService<IProcessInvoker>();

ProcessConfiguration config = new ProcessConfiguration
{
    TargetFilePath = "Path/To/Exe",
    Arguments = "With/Arguments"
};

BufferedProcessResult result = await processInvoker.ExecuteBufferedAsync(config);

The legacy subclass equivalent, for existing users only: 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 (removed)

CmdProcessInvoker and PowershellProcessInvoker were removed. Use IProcessInvoker with UseCmd() or UsePowerShell() middleware instead, as shown above.

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.1.0-alpha.1 86 9/24/2026
3.0.1 51 9/24/2026
3.0.0 97 9/13/2026
2.11.3.1 83 9/20/2026
2.11.2 88 9/13/2026
2.11.1 94 9/10/2026
2.11.0 106 9/2/2026
2.10.7 106 9/13/2026
2.10.6 96 9/10/2026
2.10.5 105 8/30/2026
2.10.4 133 8/26/2026 2.10.4 has at least one vulnerability with high severity.
2.9.4 103 8/30/2026
2.8.5 107 8/30/2026
Loading failed

#### Fixed
* Fixed an issue where ``ArgumentList`` was never copied from a user supplied ``ProcessConfiguration`` to the intermediate ``ProcessConfiguration`` that was run.
* Updated to use CliInvoke 3.0.1