Skip to content

Fix MT switch - #14682

Merged
JanProvaznik merged 3 commits into
dotnet:mainfrom
AR-May:fix-mt-switch-boolean
Aug 12, 2026
Merged

JanProvaznik merged 3 commits into
dotnet:mainfrom
AR-May:fix-mt-switch-boolean

Conversation

@AR-May

@AR-May AR-May commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

Context

 -multiThreaded  /  -mt  was a presence-only switch: any occurrence turned multi-threaded mode on, and there was no way to turn it back off. That blocks turning MT on by default later, because users would have no opt-out — including anyone who inherits  -mt  from an auto-response file or a repo's  Directory.Build.rsp . It also meant  -mt:false  silently enabled MT, the opposite of what it reads like.

 MSBUILDFORCEMULTITHREADED=1  was the only environment opt-in, and it was documented as "equivalent to passing  -mt ". Once the switch can express  false , "equivalent to  -mt " and "force" are two different things and need two different knobs.

Changes Made

  1. -mt  is now a real boolean switch: -mt  and  -mt:true  enable;  -mt:false  disables. Repeated occurrences take the last value, matching  -nodeReuse  and  -m . This holds across response files as well: the command line beats the auto-response file and  Directory.Build.rsp .

  2. Now we have two environment variables with distinct meanings
    MSBUILDFORCEMULTITHREADED=1 is Authoritative — forces MT on
    MSBUILDENABLEMULTITHREADED=1 is Soft default — MT on unless told otherwise

Resulting precedence: force env var → last  -mt  value → enable env var → off.

Testing

New unit tests

AR-May added 2 commits August 10, 2026 15:49
Support /mt, /mt:true, and /mt:false with latest-value precedence and command-line override of MSBUILDFORCEMULTITHREADED.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5015a21e-6f89-4a48-9467-bd3c9d196294
Add MSBUILDENABLEMULTITHREADED while keeping MSBUILDFORCEMULTITHREADED authoritative.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5015a21e-6f89-4a48-9467-bd3c9d196294
@AR-May
AR-May marked this pull request as ready for review August 10, 2026 15:28
Copilot AI lite review requested due to automatic review settings August 10, 2026 15:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates MSBuild’s experimental multi-threaded mode switch (-multiThreaded / -mt) to behave like a real boolean switch (including response-file precedence), and splits environment configuration into “force” vs “soft default” knobs to enable a future default-on story without removing opt-out.

Changes:

  • Make -mt/-multithreaded support :true|false (including last-one-wins semantics and correct response-file vs command-line precedence).
  • Add MSBUILDENABLEMULTITHREADED=1 as a soft default while keeping MSBUILDFORCEMULTITHREADED=1 authoritative.
  • Add resources + unit tests + documentation updates for the new parsing/precedence behavior.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/MSBuild/XMake.cs Implements precedence logic (force env var → last -mt value → enable env var → off) and adds invalid-value handling via ProcessBooleanSwitch.
src/MSBuild/CommandLine/CommandLineParser.cs Treats -mt/-multithreaded as having an optional parameter by defaulting missing values to :true.
src/MSBuild.UnitTests/XMake_Tests.cs Adds unit tests for boolean parsing, last-one-wins behavior, env-var precedence, and invalid-value rejection.
src/Framework/Traits.cs Introduces EnableMultiThreaded trait backed by MSBUILDENABLEMULTITHREADED.
src/MSBuild/Resources/Strings.resx Updates help text to show `-multithreaded[:true
src/MSBuild/Resources/xlf/Strings.cs.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.de.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.es.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.fr.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.it.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.ja.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.ko.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.pl.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.pt-BR.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.ru.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.tr.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf Localized help/source update and adds InvalidMultiThreadedValue trans-unit.
documentation/wiki/MSBuild-Environment-Variables.md Documents the split between force (MSBUILDFORCEMULTITHREADED) and soft default (MSBUILDENABLEMULTITHREADED).
documentation/specs/multithreading/multithreaded-msbuild.md Updates the multithreading spec to reflect new switch + env-var semantics and precedence.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/MSBuild/Resources/Strings.resx
Comment thread src/Framework/Traits.cs

@JanProvaznik JanProvaznik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@AR-May AR-May self-assigned this Aug 11, 2026
Comment thread documentation/wiki/MSBuild-Environment-Variables.md Outdated
Co-authored-by: Rainer Sigwald <raines@microsoft.com>
@JanProvaznik
JanProvaznik enabled auto-merge (squash) August 12, 2026 07:53
@AR-May

AR-May commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@JanProvaznik
JanProvaznik merged commit 57dd836 into dotnet:main Aug 12, 2026
12 checks passed
This was referenced Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants