Skip to sessions and notes

These session notes are AI-generated and may contain mistakes. Verify important details against the original recording.

More Processes, More Problems - how to speed up your builds with Multithreaded MSBuild

Chet Husk

Session · 25:59 recording · 7 min read

At a glance

  • Multithreaded MSBuild (-mt) in-process thread nodes
  • Elimination of multi-process IPC pipes and JIT duplication
  • Orchard Core cold builds: -23.5% (Windows), -11.9% (Linux)
  • Warm incremental builds: -68.2% (54.6s→17.4s on Windows)
  • Internal VMR build savings of 20+ minutes

Executive Summary

In this session, Chet Husk presents the biggest internal architectural evolution of the MSBuild engine in over a decade: Multithreaded MSBuild (activated via the -mt flag in .NET 11). For years, MSBuild achieved parallel builds by orchestrating multiple external operating system worker processes communicating over custom inter-process communication (IPC) pipes. While effective in simpler eras, this multi-process architecture created severe memory, CPU scheduling, and IPC serialization bottlenecks when building modern multi-targeted, heavily-referenced enterprise solutions—especially under the load of concurrent AI coding agents.

Multithreaded MSBuild collapses worker processes into a single shared engine process driven by lightweight threads. This yields an instant 23.5% reduction in cold build times on Windows and up to 68.2% reduction in warm incremental build times for large codebases like Orchard Core, while saving over 20 minutes on the internal .NET Virtual Mono Repo (VMR) CI build. Chet explains the architectural mechanics, the sidecar isolation model for legacy tasks, task enlightenment ([MSBuildMultiThreadableTask] and IMultiThreadableTask), declarative typed item bindings (ITaskItem<FileInfo>), and the newly published Roslyn analyzers and migration plugins guiding the ecosystem towards the default -mt activation in .NET 11 Feature Band 200 (11.0.200).

Core Breakthroughs & Architecture Highlights:

  1. The Multi-Process Problem: Traditional MSBuild (-m / /maxCpuCount) delegates project evaluations and target executions across separate worker OS processes. For Orchard Core (100 projects, 2+ target frameworks each = 300+ logical configurations), worker processes constantly replicate JIT overhead, assembly loads, and pass state across IPC channels.
  2. The Multithreaded Solution (-mt): Replaces process nodes with thread nodes inside a shared engine daemon. IPC is replaced with zero-overhead in-memory message passing; JIT and runtime assembly loads are amortized; process state is shared safely.
  3. Orchard Core Benchmark Results:
    • Cold Full Build: Windows drops from 116.05s to 88.74s (23.5% faster); Linux drops from 96.15s to 84.74s (11.9% faster).
    • Warm Incremental Inner Loop: Windows drops from 54.58s down to 17.36s (68.2% faster); Linux drops from 25.47s down to 22.13s (13.1% faster).
  4. VMR CI Impact: Internal production adoption across the .NET Virtual Mono Repo (VMR) reduced long-pole build times by over 20 minutes using only the -mt switch.
  5. Process Isolation & The "Current Directory" Sin: Tasks that mutate ambient process state (like Environment.CurrentDirectory or process-level environment variables) break thread safety. MSBuild 11 introduces TaskEnvironment and AbsolutePath to provide per-thread virtualized ambient state.
  6. Sidecar TaskHost Compatibility: Tasks not explicitly marked as multi-threadable are automatically routed to an out-of-process ephemeral Sidecar TaskHost, preserving 100% backward compatibility for legacy tasks while enlightened tasks run in-process at maximum speed.
  7. Task Enlightenment & Typed Bindings: Task authors mark classes with [MSBuildMultiThreadableTask], implement IMultiThreadableTask, and leverage strongly typed item bindings like ITaskItem<FileInfo> and ITaskItem<DirectoryInfo>, delegating path resolution to the engine.
  8. Roslyn Analyzers & Migration Tools: Microsoft released a dedicated analyzer package with 12 rules (flagging dangerous static state, process spawning, un-isolated file IO) plus Copilot-powered migration skills in the MSBuild repository.
  9. Roadmap to Default: Console and class libraries are fully enlightened today; packaging, publishing, and web applications are being completed for -mt to become the out-of-the-box default in .NET 11.0.200 (Winter 2026).

Detailed Section-by-Section Breakdown

1. Headline Numbers: Orchard Core Benchmarks

Presenter: Chet Husk

Chet immediately demonstrates the real-world impact of Multithreaded MSBuild on Orchard Core (a heavy real-world solution with ~100 projects and multiple target frameworks generating over 300 distinct MSBuild configurations):

Title Slide: More Processes, More Problems
Title Slide: More Processes, More Problems

  • Cold Full Build: Without changing a single line of project code, adding -mt reduces build time by 23.5% on Windows (116.05s down to 88.74s) and 11.9% on Linux (96.15s down to 84.74s).

Cold Full Build Orchard Core Benchmarks
Cold Full Build Orchard Core Benchmarks

  • Warm Incremental Inner Loop (No-Op / Minor Change): Demonstrates the elimination of pure MSBuild engine overhead. On Windows, elapsed build time plunges from 54.58s to 17.36s—a 68.2% speedup!

Warm Incremental Inner Loop Benchmarks
Warm Incremental Inner Loop Benchmarks


2. Traditional Architecture: Central Scheduler and Multi-Process Worker Nodes

To explain why -mt is necessary, Chet breaks down how MSBuild has operated since the introduction of multi-core compilation:

  • A Central Scheduling Node evaluates projects and assigns tasks to worker nodes.
  • Each worker node is a distinct OS process.
  • Each process must independently start a CoreCLR instance, load and JIT runtime DLLs, load task assemblies, and maintain an isolated state bubble.

Legacy Multi-Process MSBuild Architecture
Legacy Multi-Process MSBuild Architecture


3. State Bubbles & The Inter-Process Communication (IPC) Bottleneck

Multi-targeting multiplies the problem. In Orchard Core, 100 projects targeting two frameworks generate over 300 logical project configurations:

  • When Project A on Worker 1 references Project B on Worker 2, target outputs, item lists, and properties must be serialized over a custom binary IPC pipe.
  • As core counts increase (16, 32, 64 cores) or multiple agents run simultaneously, IPC pipes become a severe serialization bottleneck.

Project Configurations and State Bubbles
Project Configurations and State Bubbles

Interprocess Communication IPC Bottleneck
Interprocess Communication IPC Bottleneck


4. Multithreaded MSBuild (-mt): Bringing Nodes In-Process

In Multithreaded MSBuild, the worker processes are replaced with lightweight threads inside a single shared long-lived daemon process:

  • IPC Eliminated: Cross-project communication is replaced by ultra-fast in-memory pointer and message passing.
  • Shared JIT & Assembly Cache: All threads share JIT-compiled assemblies and task definitions, drastically lowering memory usage and amortizing startup overhead.
  • Engine Optimization: Profiling everything in one process allowed the team to eliminate internal lock contentions and even optimize traditional MSBuild binary log message generation.

Multithreaded MSBuild In-Process Architecture
Multithreaded MSBuild In-Process Architecture


5. Backward Compatibility: Ephemeral Sidecar Task Hosts

Because 20 years of existing MSBuild tasks assume they own the entire OS process, MSBuild 11 guarantees backward compatibility using Sidecar TaskHosts:

  • If a project invokes a legacy task that has not been marked as multi-threadable, the engine spins up an isolated sidecar process.
  • The un-enlightened task runs out-of-process with its own process state without corrupting the main engine process.
  • Once completed, the host can be reused or torn down.

Compatibility: Sidecar TaskHosts
Compatibility: Sidecar TaskHosts


6. Enlightening Tasks: Attributes and TaskEnvironment

To execute directly in-process on worker threads, task authors "enlighten" their tasks by replacing process-level ambient state with MSBuild's scoped abstractions:

  • Add the [MSBuildMultiThreadableTask] attribute.
  • Implement IMultiThreadableTask and accept TaskEnvironment.
  • Replace calls to Environment.CurrentDirectory or relative file paths with TaskEnvironment.GetAbsolutePath(...).
// Enlightened Multithreaded MSBuild Task
[MSBuildMultiThreadableTask]
public sealed class CountFileLines : Task, IMultiThreadableTask
{
    [Required]
    public string SourceFile { get; set; } = string.Empty;

    [Output]
    public int LineCount { get; set; }

    public TaskEnvironment TaskEnvironment { get; set; } = TaskEnvironment.Fallback;

    public override bool Execute()
    {
        AbsolutePath path = TaskEnvironment.GetAbsolutePath(SourceFile);
        LineCount = File.ReadLines(path).Count();
        return true;
    }
}

Enlightened Task Attributes and TaskEnvironment
Enlightened Task Attributes and TaskEnvironment


7. Modern Declarative Typed Item Bindings

MSBuild in .NET 11 introduces typed item binding, allowing task properties to declare strongly-typed file system semantics instead of raw strings:

  • By declaring ITaskItem<FileInfo> or ITaskItem<DirectoryInfo>, the MSBuild engine automatically validates inputs and resolves absolute paths before invoking Execute().
  • This removes boilerplate path calculations entirely from the task body.
// Modern Declarative Typed Item Binding
[MSBuildMultiThreadableTask]
public sealed class CountFileLines : Task, IMultiThreadableTask
{
    [Required]
    public ITaskItem<FileInfo> SourceFile { get; set; } = null!;

    [Output]
    public int LineCount { get; set; }

    public TaskEnvironment TaskEnvironment { get; set; } = TaskEnvironment.Fallback;

    public override bool Execute()
    {
        LineCount = File.ReadLines(SourceFile.Value.FullName).Count();
        return true;
    }
}

Typed Item Bindings and FullPath Support
Typed Item Bindings and FullPath Support


8. Roslyn Analyzers, AI Migration Skills & Roadmap

Chet concludes with the ecosystem rollout strategy:

  • Roslyn Analyzers: Shipped as a NuGet package (Microsoft.Build.Analyzers) containing 12 diagnostic rules that flag process spawning, relative path traversal, and mutable ambient state.
  • AI Migration Skills: Published in the official MSBuild repository for GitHub Copilot and agentic workflows to automatically inspect and upgrade legacy task codebases.
  • Release Schedule: Multithreaded mode (-mt) is available for preview testing in .NET 11 GA and is scheduled to be turned ON by default in .NET 11.0.200 (Winter 2026).
  • Public Dashboard: Track real-time MSBuild performance metrics and benchmarks at aka.ms/msbuild/performance-dashboard.