Repository navigation
Add -mt and -nodereuse switches to build scripts - #8151
Merged
Merged
Conversation
Promotes MSBuild's experimental multi-threaded mode from an env-var-only gate (MSBUILD_MT_ENABLED) to a first-class build script switch. The mode is enabled by default for local builds and is not run on CI unless explicitly requested via -mt/--mt. Implements dotnet/arcade#17242. - eng/common and src/arcade/eng/common: tools.ps1/sh resolve the default (!ci) and emit -mt; build.ps1/sh expose the -mt/--mt switch. - fsharp, roslyn, aspnetcore and nuget-client don't use eng/common/build.*, so their own build scripts gained the switch as well. - repo-projects/Directory.Build.props: replaced the MSBUILD_MT_ENABLED environment variable with the new switch, driven by DotNetBuildMT. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR promotes MSBuild’s experimental multi-threaded mode to a first-class build-script switch (-mt/--mt), defaulting on for local builds and off on CI unless explicitly requested, and updates VMR orchestration to pass the new switch instead of relying on MSBUILD_MT_ENABLED.
Changes:
- Add
-mt/--mt <true|false>option handling to multiple repo build entry points (PowerShell + shell). - Update Arcade
tools.ps1/tools.shMSBuild wrappers to emit-mtbased on resolvedmsbuildMultiThreaded/msbuild_multi_threadedinstead ofMSBUILD_MT_ENABLED. - Update
repo-projects/Directory.Build.propsto pass-mt <value>via common args (supporting opt-in and opt-out).
Show a summary per file
| File | Description |
|---|---|
| src/roslyn/eng/build.sh | Adds --msbuildMultiThreaded/--mt argument parsing. |
| src/roslyn/eng/build.ps1 | Adds -msbuildMultiThreaded/-mt parameter and CI defaulting behavior. |
| src/nuget-client/eng/dotnet-build/build.sh | Adds --mt parsing and local/CI default resolution for direct dotnet msbuild invocation. |
| src/nuget-client/eng/dotnet-build/build.ps1 | Adds -msbuildMultiThreaded/-mt parameter and CI defaulting behavior. |
| src/fsharp/eng/build.sh | Adds --msbuildMultiThreaded/--mt argument parsing. |
| src/fsharp/eng/Build.ps1 | Adds -msbuildMultiThreaded/-mt parameter and CI defaulting behavior. |
| src/aspnetcore/eng/build.sh | Adds --msbuildMultiThreaded/--mt argument parsing. |
| src/aspnetcore/eng/build.ps1 | Adds -msbuildMultiThreaded/-mt parameter, documentation, and CI defaulting behavior. |
| src/arcade/eng/common/tools.sh | Resolves msbuild_multi_threaded default and emits -mt without MSBUILD_MT_ENABLED. |
| src/arcade/eng/common/tools.ps1 | Resolves $msbuildMultiThreaded default and emits -mt without MSBUILD_MT_ENABLED. |
| src/arcade/eng/common/build.sh | Exposes -msbuildMultiThreaded/-mt switch to drive tools.sh resolution. |
| src/arcade/eng/common/build.ps1 | Exposes -msbuildMultiThreaded/-mt switch and CI behavior for Arcade build entry point. |
| repo-projects/Directory.Build.props | Replaces MSBUILD_MT_ENABLED=1 with passing -mt <value> via common args. |
| eng/common/tools.sh | Resolves msbuild_multi_threaded default and emits -mt without MSBUILD_MT_ENABLED. |
| eng/common/tools.ps1 | Resolves $msbuildMultiThreaded default and emits -mt without MSBUILD_MT_ENABLED. |
| eng/common/build.sh | Exposes -msbuildMultiThreaded/-mt switch to drive tools.sh resolution. |
| eng/common/build.ps1 | Exposes -msbuildMultiThreaded/-mt switch and CI behavior for VMR build entry point. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 17/17 changed files
- Comments generated: 6
build.sh and eng/build.ps1 are the VMR's own entry points and don't go through eng/common/build.*, so they need the switch as well. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
PowerShell [bool] parameters reject the strings 'true'/'false' and only accept $true/$false/1/0, so passing '-mt false' to a repo's build.ps1 failed with a parameter binding error. Use the existing Arcade bool build arg properties, which already map to 0/1 on Windows and true/false elsewhere, and add the missing ArcadeTrueBoolBuildArg counterpart. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
Passing -mt / --mt to the VMR root build script now also appends /p:DotNetBuildMT=<value>, so a single switch controls both the orchestrator build and every inner repo build. Also correct the -msbuildMultiThreaded usage text: PowerShell [bool] parameters reject the strings 'true'/'false', so the accepted values are '1' and '0'. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
PowerShell's [bool] parameters only bind 1/0, never the strings 'true'/'false', while the shell scripts previously only understood true/false. That forced every caller to pick a different value per OS. Normalize 1/0 to true/false in tools.sh for the boolean build args (-nodeReuse, -warnAsError, -msbuildMultiThreaded), so 1/0 is now the one form that works everywhere. ArcadeTrueBoolBuildArg and ArcadeFalseBoolBuildArg therefore no longer need to vary by OS. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
Now that 1/0 works on every platform the ArcadeTrueBoolBuildArg and ArcadeFalseBoolBuildArg properties add no value, so inline them at their only use site and remove them. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
Give -nodeReuse the same treatment as -mt: an explicitly passed value now wins over the CI default, which removes the need for the internal MSBUILD_NODEREUSE_ENABLED environment variable (dotnet/arcade#17013). - eng/common/{build,msbuild}.{ps1,sh}: node reuse and MSBuild's multi-threaded mode are only forced off on CI when the corresponding switch wasn't passed explicitly. - eng/common/msbuild.{ps1,sh}: add the -mt / --mt switch, matching build.{ps1,sh}. - eng/common/tools.{ps1,sh}: drop the hard error that failed CI builds when node reuse was enabled, so it can be opted into explicitly. - eng/build.ps1, build.sh: accept -nodeReuse and flow it down to the repo builds as /p:DotNetBuildNodeReuse. - repo-projects/Directory.Build.props: replace the MSBUILD_NODEREUSE_ENABLED environment variable with a -nodeReuse 1|0 argument driven by DotNetBuildNodeReuse, next to the existing -mt argument. The src/arcade/eng/common copies are kept in sync. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
fsharp, roslyn, aspnetcore and nuget-client don't use eng/common/build.*,
so they need the -nodeReuse switch too now that the VMR flows it down.
fsharp and roslyn rejected it outright ("Invalid argument").
- fsharp, roslyn: add the --nodeReuse / -nodeReuse argument. roslyn keeps
the !ci default; fsharp keeps node reuse off by default, which is what
it forced before.
- aspnetcore: keep disabling node reuse (and MSBUILDDISABLENODEREUSE) by
default, but let an explicitly passed value win. This also fixes the
shell script setting the unused nodeReuse variable instead of node_reuse.
- nuget-client: an explicit --nodeReuse value now wins over the CI
default, matching --msbuildMultiThreaded.
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
…apper src/msbuild/eng/build.ps1 re-invokes eng/common/build.ps1 out-of-proc with `pwsh -File`, which passes every argument as a literal string. Typed Arcade parameters such as [bool] $nodeReuse and [bool] $msbuildMultiThreaded cannot bind to a string, so `-mt 1` failed with: Cannot process argument transformation on parameter 'msbuildMultiThreaded'. Switch to `pwsh -Command`, which re-parses the arguments as PowerShell so `-mt 1` arrives as an integer. This matches what src/runtime/eng/Build.ps1 already does via Invoke-Expression, and what src/msbuild/build.cmd already does when it calls this script. The build still runs out-of-proc so that stage 2 does not inherit stage 1's state variables. Arguments that are not simple tokens are single-quoted so they survive the re-parse (e.g. -warnnotaserror NU1901;NU1902;NU1903, and paths with spaces), while bare tokens such as `1` stay unquoted so they keep their type. `-Command` does not propagate a script's `exit N`, so the generated command ends with `exit $LASTEXITCODE`, pre-seeded to 1 so that a failure which prevents the script from running at all is not reported as success. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
Member
Author
|
Validation build with -mt and -nodeReuse turned on in CI: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1542440&view=results |
The -mt switch was enabled by default for local builds and disabled on CI. Keep the switch and all of its plumbing, but default it to off everywhere until MSBuild's multi-threaded mode has proven out. Explicitly passing -mt/--mt (or /p:DotNetBuildMT) still wins, on CI and locally. Since the default is now off regardless of -ci, the blocks that forced it off on CI are redundant and are removed. The equivalent nodeReuse handling is untouched. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
JanProvaznik
approved these changes
Aug 10, 2026
This was referenced Aug 12, 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.
Implements dotnet/arcade#17242.
MSBuild's experimental multi-threaded mode was previously gated behind an internal
MSBUILD_MT_ENABLEDenvironment variable. This promotes it to a first-class build script switch.The switch defaults to off for now, on CI and locally, so this is a no-op for existing builds. Enabling it by default for local builds is deliberately deferred until the mode has proven out; that will be a one-line change per
tools.ps1/tools.sh.Resolution semantics
Identical across the PowerShell and shell variants:
-mt/--mtvalue always wins, on CI and locally.tools.ps1/tools.shown the default resolution and emit-mt; the build scripts just expose the switch.-mttakes a value, consistent with the existing-nodeReuseand-warnAsErrorparameters:Changes
eng/commonandsrc/arcade/eng/commontools.ps1/tools.shresolve$msbuildMultiThreaded/msbuild_multi_threadedand emit-mt;build.ps1/build.shexpose-mt <value>(long form-msbuildMultiThreaded)build.shandeng/build.ps1eng/common/build.*, so they expose the switch directly. An explicit value is also flowed down as/p:DotNetBuildMT=<value>, so a single-mt 0covers the orchestrator and every repo build.fsharp,roslyn,aspnetcore,nuget-clienteng/common/build.*, so their own build scripts gained-mtand-nodeReuse.nuget-client'seng/dotnet-build/build.shinvokesmsbuilddirectly and therefore resolves the defaults itself.repo-projects/Directory.Build.propsMSBUILD_MT_ENABLED=1environment variable with the new switch.DotNetBuildMTnow passes-mt <value>, so it can be used to opt out as well as in.All other repos pick the change up automatically — the
UpdateEngCommonFilestarget copies the VMR'seng/commonover everysrc/<repo>/eng/commonbefore that repo builds.Repos with custom build scripts
fsharp,roslyn,aspnetcoreandnuget-clientdon't calleng/common/build.*directly, so both switches had to be added to their own scripts.fsharpandroslynreject unknown arguments outright, andaspnetcore,fsharpandnuget-clienthard-disabled node reuse, so an explicitly passed value was silently dropped. Each script now declares the parameter and only applies its own default when the caller didn't specify one.msbuildandruntimedo forward unrecognized arguments toeng/common/build.*, but onlyruntimedid so in a way that preserves argument types.msbuild's wrapper re-invoked Arcade withpwsh -File, which passes every argument as a literal string, and a PowerShell[bool]parameter can never bind from a string:It now uses
pwsh -Command, which re-parses the arguments as PowerShell so-mt 1arrives as an integer — the same thingruntime's wrapper achieves withInvoke-Expression, and whatmsbuild's ownbuild.cmdalready does when it calls this script. The build still runs out-of-proc so that stage 2 doesn't inherit stage 1's state variables.Hard-disabling node reuse is worth fixing at the source, since it also defeats MSBuild Server. Filed dotnet/aspnetcore#68251 and dotnet/fsharp#20217; the changes here are a stop-gap.
-nodeReusegets the same treatmentAlso implements dotnet/arcade#17013.
Node reuse was gated the same way, behind an internal
MSBUILD_NODEREUSE_ENABLEDenvironment variable, with the added twist thattools.ps1/tools.shhard-failed any CI build that had node reuse enabled.-nodeReusealready existed as a parameter, it just couldn't be turned on for a CI build.It now works the same way as
-mtin that an explicitly passed value wins, on CI and locally. Unlike-mtits default is unchanged:!ci, i.e. on for local builds and off on CI. TheMSBUILD_NODEREUSE_ENABLEDenvironment variable and the CI hard error are gone, andeng/build.ps1/build.shflow an explicit value down as/p:DotNetBuildNodeReuse, whichrepo-projects/Directory.Build.propsturns into-nodeReuse 1|0for every repo build.msbuild.ps1/msbuild.shgained the-mtswitch as well, so the two smaller entry points behave likebuild.ps1/build.sh.Drive-by:
1/0is now accepted by the shell scriptsPowerShell's
[bool]parameters only bind$true/$false/1/0— passing the stringtrueorfalsethrows aParameterBindingArgumentTransformationException. The shell scripts, on the other hand, only understoodtrue/false. That meant a caller driving both (likerepo-projects/Directory.Build.props) had to pick a different value per OS.tools.shnow normalizes1/0totrue/falsefor the boolean build arguments —-nodeReuse,-warnAsErrorand-msbuildMultiThreaded— so1/0is the one form that works everywhere. Normalization happens on the variable rather than at the comparison, so values forwarded straight to MSBuild (/nr:$node_reuse,/p:TreatWarningsAsErrors=$warn_as_error) stay valid. Empty still means "not specified".This is why the per-OS
ArcadeTrueBoolBuildArg/ArcadeFalseBoolBuildArgproperties could be removed.Validation
.ps1files parse cleanly; all modified.shfiles passbash -n.tools.sh,eng/common/build.shandeng/common/build.ps1.-mtis suppressed by default both locally and on CI, and emitted for-mt 1in either case.-mtmatrix against the realeng/common/build.ps1parameter block and the realtools.ps1/tools.shresolution lines: unset locally, unset on CI,-mt 1,-mt 0,-ci -mt 1,-ci -mt 0and the long-form-msbuildMultiThreadedall resolve identically on both platforms.dotnet msbuild -getProperty:CommonArgson a repo project confirms no-mtby default,-mt 1withDotNetBuildMT=true, and-mt 0withDotNetBuildMT=false.-mtresolves to aBooleanparameter with themtalias on all six PowerShell entry points, and--mt 0is accepted by theroslyn/fsharpshell scripts (which reject unknown arguments).1/0,true/falseand the unset case all resolve identically throughtools.sh, and that--mt 1propagates as/p:DotNetBuildMT=true.dotnet msbuild -mtis accepted by the MSBuild version in this repo (18.9).-nodeReusematrix on both platforms: off by default on CI, on by default locally,-ci -nodeReuse 1yields/nr:true, and-nodeReuse 1|0propagates as/p:DotNetBuildNodeReuse.dotnet msbuild -getProperty:CommonArgsconfirms-nodeReuse 1|0is only emitted whenDotNetBuildNodeReuseis set.MSBUILD_MT_ENABLEDandMSBUILD_NODEREUSE_ENABLEDno longer appear anywhere in the repository.msbuild's wrapper was replayed against the real Arcade parameter block with the exact command line that failed in CI:-mt 1 -nodeReuse 1now bind as booleans,-mt 0yieldsFalse, every/p:and/clp:argument survives (including one containing spaces) along withNU1901;NU1902;NU1903, exit codes propagate through both process hops, and a genuine parameter binding failure exits non-zero.Note
-mtrequires MSBuild 18+. Repos built with-msbuildEngine vs(for exampleaspnetcoreon Windows) fail withMSB1001on a VS 17.x install if-mtis passed. This isn't hit while the switch defaults to off, but it needs resolving before the default is flipped.Note
This pull request description was generated with GitHub Copilot.