Migrating from V3 to V4
This guide takes a pipeline from V3.2.8 (the last V3 release) to V4.0.0.
Most pipelines only need the six changes on this page. Every other page covers one area. Read only the ones for features you use.
Before you start
- Use a .NET 11 SDK and runtime for the pipeline project and the CI runner. The applications your pipeline builds keep their own target frameworks.
- Use C# 14 or later. The
context.Tools.<Tool>properties need it. - Upgrade every ModularPipelines package together, including custom integration projects and test helpers.
Staying on 3.x for now? Read the v3.2.8 documentation source. If you used a V4 pre-release build, also check the GitHub releases.
The six changes most pipelines need
1. Register and run on the builder
// V3
builder.Services.AddModule<BuildModule>();
await builder.Build().RunAsync(); // or builder.ExecutePipelineAsync()
// V4
builder.AddModule<BuildModule>();
await builder.RunAsync();
Ordinary DI registrations stay on builder.Services.
More: Entry point and options.
2. Options are immutable
// V3
builder.Options.ExecutionMode = ExecutionMode.WaitForAllModules;
builder.Options.PrintLogo = false;
// V4
builder.ConfigureOptions(options => options with
{
FailureMode = FailureMode.ContinueOnFailure,
Console = options.Console with { PrintLogo = false },
});
More: Pipeline options.
3. Configure takes a builder and returns nothing
Dependencies, categories, tags, and retries all move into it.
// V3
protected override ModuleConfiguration Configure() => ModuleConfiguration.Create()
.WithRetryCount(3)
.Build();
// V4
protected override void Configure(ModuleConfigurationBuilder module) => module
.WithRetry(3);
More: Modules.
4. One namespace for core types
Start module files with using ModularPipelines;. Remove using ModularPipelines.Models;,
using ModularPipelines.Modules;, and using ModularPipelines.Extensions;.
More: Packages and namespaces.
5. Results are not implicitly nullable
Module<T> now returns Task<T>, not Task<T?>. Result checks use typed variants, and the
summary exposes results directly.
// V3
protected override async Task<BuildOutput?> ExecuteAsync(...)
var results = await summary.GetModuleResultsAsync();
// V4
protected override async Task<BuildOutput> ExecuteAsync(...)
var results = summary.Results;
More: Modules and Results and summaries.
6. Tools move to context.Tools, and commands end in Async
// V3
await context.DotNet().Build(options, cancellationToken: cancellationToken);
// V4
await context.Tools.DotNet.BuildAsync(options, cancellationToken: cancellationToken);
Tool options were regenerated from current CLI help, so some option names and types differ. More: Tools and commands and CLI options.
Complete example
A pipeline that restores and builds a project, before and after.
V3
using ModularPipelines;
using ModularPipelines.Attributes;
using ModularPipelines.Configuration;
using ModularPipelines.Context;
using ModularPipelines.DotNet.Extensions;
using ModularPipelines.DotNet.Options;
using ModularPipelines.Extensions;
using ModularPipelines.Models;
using ModularPipelines.Modules;
using ModularPipelines.Options;
var builder = Pipeline.CreateBuilder(args);
builder.Options.ExecutionMode = ExecutionMode.WaitForAllModules;
builder.Services.AddModule<RestoreModule>();
builder.Services.AddModule<BuildModule>();
await builder.Build().RunAsync();
public class RestoreModule : Module<CommandResult>
{
protected override async Task<CommandResult?> ExecuteAsync(
IModuleContext context, CancellationToken cancellationToken)
=> await context.DotNet().Restore(new DotNetRestoreOptions(), cancellationToken: cancellationToken);
}
[DependsOn<RestoreModule>]
public class BuildModule : Module<CommandResult>
{
protected override ModuleConfiguration Configure() => ModuleConfiguration.Create()
.WithRetryCount(2)
.Build();
protected override async Task<CommandResult?> ExecuteAsync(
IModuleContext context, CancellationToken cancellationToken)
=> await context.DotNet().Build(
new DotNetBuildOptions { Configuration = "Release", NoRestore = true },
cancellationToken: cancellationToken);
}
V4
using ModularPipelines;
using ModularPipelines.Context;
using ModularPipelines.DotNet.Options;
using ModularPipelines.Options;
var builder = Pipeline.CreateBuilder(args);
builder.ConfigureOptions(options => options with
{
FailureMode = FailureMode.ContinueOnFailure,
});
builder.AddModule<RestoreModule>().AddModule<BuildModule>();
await builder.RunAsync();
public class RestoreModule : Module<CommandResult>
{
protected override Task<CommandResult> ExecuteAsync(
IModuleContext context, CancellationToken cancellationToken)
=> context.Tools.DotNet.RestoreAsync(
new DotNetRestoreOptions(), cancellationToken: cancellationToken);
}
[DependsOn<RestoreModule>]
public class BuildModule : Module<CommandResult>
{
protected override void Configure(ModuleConfigurationBuilder module) => module
.WithRetry(2);
protected override Task<CommandResult> ExecuteAsync(
IModuleContext context, CancellationToken cancellationToken)
=> context.Tools.DotNet.BuildAsync(
new DotNetBuildOptions { Configuration = "Release", NoRestore = true },
cancellationToken: cancellationToken);
}
Migration steps
Work in this order. Earlier steps clear the most compiler errors.
- Upgrade packages and the SDK. See Packages and namespaces.
- Fix namespaces. See Packages and namespaces.
- Fix the entry point and options. See Entry point and options.
- Fix each module:
Configure, dependencies, retries, and return types. See Modules. - Fix result and summary access. See Results and summaries.
- Fix tool and command calls. See Tools and commands, CLI options, and Integration packages (Git changed the most).
- Fix whatever else you use. Each of these is its own page: hooks and plugins, conditions and requirements, context services, logging and HTTP, files and utilities, exceptions and extension points.
- Once it compiles, read Runtime behavior changes. These do not produce compiler errors. At minimum, ignore or disable the new run history folder.
- Build and test the migrated pipeline, including command arguments and failure and skip paths, before you run deployment modules.
Stuck on a compiler error? Look it up in the old-to-new API lookup. Using a coding agent? Point it at the agent reference.
What has not changed
These still work, although some types moved namespace:
Pipeline.CreateBuilder(args), direct configuration access, and constructor dependency injection.Module<T>andSyncModule<T>,[DependsOn<T>], categories, and tags.await context.GetModule<TModule>()andGetModuleIfRegistered<TModule>().- The
context.Files,context.Data,context.Network,context.Environment, andcontext.Securitygroups. - Logging through
context.Logger.LogInformation(...)and the otherILoggerextensions. - Module virtual lifecycle hooks, including replacing a result in
OnAfterExecuteAsync. - Separate tool options and
CommandExecutionOptionsparameters. ValueOrDefault,ExceptionOrDefault,SkipDecisionOrDefault,Match, andSwitchon results.
Do not apply the V2-to-V3 changes again. IModuleContext and context.GetModule<T>() already
exist in V3.
New in V4
None of these are needed to migrate.
- Pipeline CLI: selection, validation, and dry-run planning.
- Fingerprint-based caching, with a pipeline-wide disable switch.
- Run reports and local history, including correlation, duration comparisons, and bounded output excerpts.
- OpenTelemetry, dependency graph export, and richer CI output.
- Testing helpers and F# module support.
- Trimming and Native AOT for supported statically described C# pipelines.
- Distributed execution, artifact contracts, worker capabilities, and execution backends. These packages are not in V3.2.8. If you used them from an intermediate build, see the distributed configuration guide.
- More CLI integrations, and much wider command coverage in existing ones.
- Command interceptors.
ModularPipelines.ICommandInterceptorwraps command execution as middleware throughInvokeAsync(invocation, next, cancellationToken). Register one withbuilder.AddCommandInterceptor<T>()orAddCommandInterceptor(instance). See Testing. - Planning-safe conditions. Mark a condition or attribute with
IPlanningSafewhen dry-run planning may evaluate it. See Run conditions. - The
OnCachedResultAsyncmodule hook,ModuleResult<T>.TryGetValue, fluentWithExecutionHint,WithPriority, andWithNotInParallel, andcontext.Tools.Git.Changes.HasChangesAsync.
Getting help
- Check the linked feature guides and the installed V4 package's signatures for the failing API.
- Review the current examples.
- Search or open a GitHub issue. Include the old and new package versions, a minimal module or command example, and the compiler or runtime error.