Getting Started
This page takes you from installing the package to running your first process and reading its result. Start here
if you are adding Invex.Process to a host, tool or build for the first time.
Installation
dotnet add package Invex.Process
The package targets net10.0.
Register the service
Add the process runner to your dependency injection container once during host setup:
using Invex.Process;
using Microsoft.Extensions.Hosting;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddProcessRunner();
AddProcessRunner() registers IProcessRunner as a singleton. The runner is stateless, so a
single instance can safely serve concurrent callers.
Note
The runner logs through ILogger<ProcessRunner>, so make sure logging is configured on the host
(it is by default with Host.CreateApplicationBuilder).
Run your first process
Inject IProcessRunner and call RunAsync (or the synchronous Run):
using Invex.Process;
public sealed class VersionReporter(IProcessRunner processRunner)
{
public async Task<string> GetDotnetVersionAsync(CancellationToken cancellationToken)
{
var result = await processRunner.RunAsync(
new ProcessRunOptions("dotnet", "--version"),
cancellationToken);
return result.Output.Trim();
}
}
When this runs you'll see log entries like:
info: Invex.Process.ProcessRunner[0]
Run: dotnet --version
dbug: Invex.Process.ProcessRunner[0]
10.0.100
What you get back
Both Run and RunAsync return a ProcessRunResult:
| Property | Description |
|---|---|
ExitCode |
The process exit code. Zero unless AllowFailedResult was set (a non-zero code otherwise throws). |
Output |
The complete captured stdout, one line per Environment.NewLine. |
Error |
The complete captured stderr. |
RunOptions |
The options the process was started with. |
The output is always fully captured — even if you turn logging down or off entirely.
Next steps
- Running Processes: arguments, working directories, environment variables.
- Handling Failures: what happens when the exit code isn't zero.
- Logging: tune how invocations and output are logged.
- IProcessRunner, ProcessRunOptions and ProcessRunResult in the API reference.