Add new multithreaded APIs - #12625
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces core APIs to enable thread-safe task execution in MSBuild's multithreaded execution model. The changes provide safe alternatives to global process state operations, allowing IMultithreadable tasks to run concurrently within a single MSBuild process.
Key changes:
- New
TaskEnvironmentclass providing thread-safe environment variable and path operations AbsolutePathstruct for safe path handlingIMultiThreadableTaskinterface for tasks that can execute in parallelMSBuildMultiThreadableTaskAttributefor marking existing tasks as thread-safe
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Framework/TaskEnvironment.cs | Core API providing thread-safe environment operations and path resolution |
| src/Framework/PathHelpers/AbsolutePath.cs | Immutable struct representing absolute file system paths |
| src/Framework/IMultiThreadableTask.cs | Interface for tasks capable of thread-safe execution |
| src/Framework/MSBuildMultiThreadableTaskAttribute.cs | Attribute for marking existing tasks as thread-safe |
| documentation/specs/multithreading/thread-safe-tasks.md | Updates to specification removing virtual modifiers |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
JanProvaznik
reviewed
Oct 9, 2025
JanProvaznik
left a comment
Member
There was a problem hiding this comment.
just venting some thoughts about doc comments, the shape of the code is good, approved, but needs another reviewer
Member
|
I added a bit of fit-and-finish to the existing API docs because I couldn't help myself. |
baronfel
approved these changes
Oct 13, 2025
This was referenced Oct 15, 2025
This was referenced Feb 23, 2026
Merged
Merged
This was referenced Aug 17, 2026
ViktorHofer
added a commit
to dotnet/dotnet
that referenced
this pull request
Aug 21, 2026
Under MSBuild's multi-threaded mode (-mt), TaskRouter routes every task that lacks [MSBuildMultiThreadableTask] to an out-of-proc sidecar TaskHost. In the VMR runtime inner build this raised TaskHost invocations from 849 to 14,125 and added ~98s of net task time, cancelling out most of the expected -mt savings. Analysis -------- Every concrete Arcade task (136 total) was checked against the rule set from dotnet/msbuild src/TaskAnalyzer - the MSBuildTask0001/0002/0004 banned-API tables plus static mutable state - using a Roslyn walker with transitive call-chain analysis, so violations reached through shared helpers are caught. MSBuildTask0003 (relative paths) is not treated as a blocker: MSBuild's own Copy, Exec, Unzip, ZipDirectory and every ToolTask-derived tool task carry the attribute. The bar applied here is no process-global state (env vars, cwd, Path.GetFullPath/GetTempPath, Console.*, Process.Start) and no unsynchronized static mutable state. 44 tasks came back clean and are annotated. The remaining 92 need code changes and are tracked in dotnet/arcade#17378; most are blocked by a shared helper (PackageIndex, LocateDotNet, the Helix/AzDO client stack, the publishing stack) rather than by the task itself. MSBuild package bump -------------------- MSBuildMultiThreadableTaskAttribute was added in dotnet/msbuild#12625 and first shipped in 18.3.x, so the 17.12.50 pin could not compile it. Bumped to 18.4.0, which ships net472 and net10.0 libs matching Arcade's NetMinimum. This is runtime-safe on older hosts: AssemblyTaskFactory only calls TaskRouter.NeedsTaskHostInMultiThreadedMode when BuildParameters.MultiThreaded is true, so a 17.x host never enumerates the attribute. TargetFrameworkResolver race ---------------------------- TargetFrameworkResolver.CreateOrGet used an unsynchronized static readonly Dictionary with TryGetValue/Add. Switched to ConcurrentDictionary.GetOrAdd, which is both a correctness fix and what unblocks the two hottest tasks - ChooseBestP2PTargetFrameworkTask (1740 invocations, +16.1s under -mt) and ChooseBestTargetFrameworksTask (1195 invocations, +12.2s), together roughly 35% of the measured TaskHost overhead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Aug 24, 2026
This was referenced Sep 1, 2026
This was referenced Sep 9, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #11828
Changes:
This PR introduces the core APIs that enable thread-safe task execution in MSBuild's multithreaded execution model. These APIs provide safe alternatives to global process state operations, allowing
IMultithreadabletasks to run concurrently within a single MSBuild process.Node:
Adding multithreaded APIs in order to unblock #12617
Extracted APIs from #12608