Repository navigation
[ci] Enable MSBuild multithreaded mode with MSBUILDENABLEMULTITHREADED - #13753
jonathanpeppers wants to merge 4 commits into
Conversation
Set MSBUILDENABLEMULTITHREADED=1 in the shared CI variables so MSBuild runs with -mt by default. Set it to 0 for the signing stages and the macOS entitlements step, because they run VS MSBuild.exe and signing tooling that has not been validated in multithreaded mode. Co-authored-by: Copilot App <[email protected]>
Prepare.proj runs on the bootstrap SDK and <Exec/>s the local SDK. The outer dotnet sets MSBuildSDKsPath to its own Sdks folder, and the inner dotnet keeps an inherited value, so the inner build imported the bootstrap SDK's Microsoft.NET.Sdk. With -mt, GenerateResource runs in a .NET task host started from $(NetCoreSdkRoot) of that SDK, and the handshake with the newer MSBuild fails with MSB4216. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
`make prepare` ran Prepare.proj with the system `dotnet`, and Prepare.proj then runs the local SDK with <Exec/>. The child inherited the outer SDK's MSBuildSDKsPath, so the local MSBuild imported the system SDK's Microsoft.NET.Sdk. With -mt this fails with MSB4216. `install-dotnet` runs first, so run Prepare.proj with the local SDK and drop the MSBuildSDKsPath workaround and the unused SYSTEM_DOTNET_BINLOG helper. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The new default makes non-multithreaded test cases run multithreaded too; both false branches need explicit -mt:false to preserve ordinary MSBuild coverage.
1 open issue
What changed in this PR
Enables MSBuild multithreaded mode by default in CI, including builds launched by tests, while adding targeted signing opt-outs. Updates Unix preparation to use the local SDK and avoid mixing SDK versions in nested builds.
Changes:
- Sets
MSBUILDENABLEMULTITHREADED=1globally in CI, preserving explicit-mt:falseoverrides. - Disables the environment-variable default for release signing and macOS entitlements steps.
- Switches
make prepareto the local SDK, removes the unused system-dotnet helper, and documents CI behavior.
| File | Description |
|---|---|
Makefile |
Runs preparation with the local SDK. |
Documentation/guides/MSBuildBestPractices.md |
Documents multithreaded CI defaults and opt-outs. |
build-tools/scripts/msbuild.mk |
Removes the unused system-dotnet helper. |
build-tools/automation/yaml-templates/variables.yaml |
Enables multithreaded mode by default. |
build-tools/automation/yaml-templates/commercial-build.yaml |
Adds an opt-out for macOS entitlements. |
build-tools/automation/yaml-templates/build-macos.yaml |
Adds an opt-out for macOS entitlements. |
build-tools/automation/azure-pipelines.yaml |
Adds a release-signing stage opt-out. |
build-tools/automation/azure-pipelines-internal.yaml |
Adds a signing and MSI creation stage opt-out. |
Review effort: Balanced
| - name: MSBUILDENABLEMULTITHREADED | ||
| value: '1' |
|
🤖 Evidence that CI ran MSBuild in I replayed the
Both builds ran the same command line ( The task host launches are tasks that are not marked as multithreaded-safe, which MSBuild moves out of process only in The other 14 are SourceLink tasks ( Limit: these binlogs cover only the Android tools test build. A successful run does not upload binlogs for the SDK build ( |

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
9390e4a4af49abb251175b5c87e85fda71dfc2c1Prepare.projrun with the local 12.0 alpha SDK under-mtsucceeded end to end; binlog shows strict multithreaded mode and the 12.0 alphaMSBuildSDKsPath.↓ The
Makefilechange itself was not run (no macOS/Linux machine); CI has not run on this revision.↓ Later build steps (
make jenkins, tests) under-mtare not verified.MSBuildSDKsPathcauses it (DOTNET_HOST_PATHandMSBuildExtensionsPathalone pass).dotnet-bootstrap/sdk/11.0.100-rc.3.26522.148/MSBuildfrom thePrepare.proj<Exec/>, which matches the repro.Context: https://github.com/dotnet/msbuild/blob/main/documentation/wiki/MSBuild-Environment-Variables.md
Context: #12061
MSBuild reads
MSBUILDENABLEMULTITHREADED=1and then runs as if-mtwas passed. An explicit-mt:falsestill turns it off. Set it invariables.yamlso every CI build, including the sample projects that tests build, runs in multithreaded mode.The signing stages (
dotnet_prepare_releasein the official and internal pipelines) and the macOS entitlements step set it to0. The internal job builds workload MSIs with VSMSBuild.exe, which Arcade keeps out of-mt(dotnet/dotnet#9989). The opt-out applies on all branches, somainsigns the same way asrelease/*. The internal signing steps still get-mtfrom Arcade'sbuild.ps1for the outerdotnetbuild, as they do today.MSBUILDFORCEMULTITHREADED=1also exists, but it ignores-mt:false, so it is not used.make prepareuses the local SDKWith
-mt, macOSmake preparefailed:Since #12061,
make preparerunsPrepare.projwith the systemdotnet, andPrepare.projruns<Exec/>on the local SDK ($(DotNetPreviewTool)). ThedotnetCLI setsMSBuildSDKsPathto its ownSdksfolder before it runs MSBuild, and a childdotnetkeeps an inherited value. So the local MSBuild imported the system SDK'sMicrosoft.NET.Sdk. That mix worked until now. With-mt,GenerateResourceruns in a .NET task host that starts from that SDK's$(NetCoreSdkRoot), and its handshake with the newer MSBuild fails.make preparealready runsinstall-dotnetfirst, soPrepare.projnow runs with the local SDK, and the outer and inner builds use the same SDK. TheSYSTEM_DOTNET_BINLOGhelper has no other callers and is removed. On Windows CI,Prepareruns on a clean agent before the local SDK exists, so$(DotNetPreviewTool)is the systemdotnetand there is no mix.Validation
-v:diagloggedMulti-threaded strict mode is enabledwith the variable set, and did not with-mt:false.6e6f978f) andrelease/11.0.1xxboth read the variable inTraits.cs.<Exec/>of the 12.0.100-alpha.1.26556.115dotnet buildon a project with a.resxgave the same MSB4216. Setting each inherited variable by itself showed that onlyMSBuildSDKsPathfails (303 s timeout);DOTNET_HOST_PATHandMSBuildExtensionsPathalone pass.MSBUILDENABLEMULTITHREADED=1 bin/Debug/dotnet/dotnet build build-tools/scripts/Prepare.proj -t:Prepareon Windows (local 12.0 alpha SDK as the outer build, BaseTasksobjdeleted first): succeeded. The BootstrapTasks binlog shows strict multithreaded mode and the 12.0 alphaMSBuildSDKsPath.Makefilechange was not run locally (no macOS/Linux machine). The rest of the SDK build and tests were not run locally under-mt.