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 Jul 16, 2026
Closed
This was referenced Jul 23, 2026
JoeRobich
added a commit
to dotnet/roslyn
that referenced
this pull request
Jul 24, 2026
…nalyzers multithreadable (#84343) Enables the compiler MSBuild tasks (Csc/Vbc/etc.) to adopt MSBuild's multithreaded task execution model, and marks the first such task. details: https://github.com/dotnet/msbuild/blob/main/documentation/specs/multithreading/multithreaded-msbuild.md ## Changes **1. Bump `Microsoft.Build` to 18.7.1 and align the lagging `System.*` to the 10.0.8 band** (`eng/Packages.props`, `eng/Versions.props`, `eng/Version.Details.xml`, `eng/Version.Details.props`) The multithreaded task APIs (`MSBuildMultiThreadableTaskAttribute`, `IMultiThreadableTask`, `TaskEnvironment`, `AbsolutePath`; dotnet/msbuild#12625) were added in **Microsoft.Build 18.4.0**; this bumps all three central groups (source-build, net10.0, net472) to **18.7.1**. 18.7.1's dependency closure requires `System.*` at **10.0.4+**. `main` already flowed the core runtime `System.*` (`System.Collections.Immutable`, `System.Text.Json`, `System.Reflection.Metadata`, `System.Threading.Tasks.Dataflow`, `System.Text.Encodings.Web`, `System.IO.Pipelines`, `Microsoft.Bcl.AsyncInterfaces`, …) to **10.0.8** via #84402, which already satisfies 18.7.1. This PR only needs to bring the packages that still lagged to the same **10.0.8** band: - **Peripheral darc-flowed `System.*`** that are pulled in only transitively via MSBuild (`Version.Details.xml` + `Version.Details.props`): `System.Configuration.ConfigurationManager`, `System.Diagnostics.EventLog`, `System.Security.Cryptography.ProtectedData`, `System.Resources.Extensions`. - **Hand-maintained literals:** `System.CodeDom` (`Packages.props`), `System.Security.Cryptography.Pkcs`/`Xml` (`Versions.props`, both source-build and non-source-build groups). The net8.0 BuildHost is unaffected — it pins its own Microsoft.Build version via `VersionOverride`/`PackageDownloadAndReference` (17.11.48, the oldest version compatible with its NetCore TFM), so it does not consume these central groups. **2. Mark `ShowMessageForImplicitlySkipAnalyzers` with `[MSBuildMultiThreadableTask]`** Its `Execute()` only logs a message — no working directory, environment variable, process, file I/O, or static-field usage — so the attribute alone is sufficient; it does not need `IMultiThreadableTask`/`TaskEnvironment`. All build flavors reference 18.7.1, so the attribute is applied unconditionally (no `#if`). **3. Fix `ErrorLoggingEngine` for the 18.6+ assembly move** (`TestUtilities/ErrorLoggerEngine.cs`) The internal `Microsoft.Build.Shared.EventArgsFormatting` helper this reflects into moved from `Microsoft.Build.dll` to `Microsoft.Build.Framework.dll` in MSBuild 18.6+, so it now loads from `Microsoft.Build.Framework.dll`. ## Validation **Local (bootstrapped SDK against current main):** - **Full solution restore: 0 errors, no NU1109** across the whole `Roslyn.slnx`. - `Microsoft.Build.Tasks.CodeAnalysis.UnitTests`: **net10.0 and net472 both green**, including `TargetTests.TestImplicitlySkipAnalyzers` (previously MSB4062 without the attribute type) and `VbcTests.CheckErrorAndWarningParsing` (exercises the `EventArgsFormatting` reflection). Task + test assemblies build clean on both TFMs with `TreatWarningsAsErrors`, and the net10.0 task assembly carries `Microsoft.Build.Framework.MSBuildMultiThreadableTaskAttribute`. **CI:** fully green — all 28 checks pass, including **Source-Build (Managed)** (confirms 18.7.1 + the 10.0.8 band are available in the source-build feed), all CoreClr/net10.0 test legs, VS integration, and the Desktop test legs. ## Reviewer notes - **darc file edits:** the four peripheral `System.*` packages are aligned to 10.0.8 by editing `Version.Details.xml` + `Version.Details.props` directly (they lagged at 10.0.1 because nothing references them except transitively via MSBuild). This mirrors the manual `System.*` alignment in #84262; flagging since it touches darc-managed versions. They will be re-flowed on the next runtime dependency update. - **Source-build MSBuild bump:** this raises the `DotNetBuildSourceOnly` group to 18.7.1; the CI **Source-Build (Managed)** leg (green) confirms 18.7.1 + the 10.0.8 band are available in the source-build feed. - **Known-flaky legs:** the Desktop (.NET Framework) `Test_Windows_Desktop_*` legs sometimes fail on unrelated `Editor.CSharp`/`Razor`/`CodeStyle` host crashes; they passed on the latest run. ## Not in this PR `Csc` / `Vbc` are **not** migrated yet — they still source the compile working directory from `Directory.GetCurrentDirectory()` (`ManagedCompiler.CurrentDirectoryToUse`) and read `Environment.GetEnvironmentVariable("LIB")` (`LibDirectoryToUse`), both of which need real `TaskEnvironment` plumbing. This PR makes the 18.7.1 API available so that work can follow. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Joey Robichaud <jorobich@microsoft.com>
This was referenced Jul 27, 2026
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