Skip to content

[release/11.0.1xx] Forward MSBuild -mt switches to the build engine - #56207

Merged
JanProvaznik merged 2 commits into
dotnet:release/11.0.1xxfrom
JanProvaznik:backport/pr-56120-release-11.0.1xx
Sep 10, 2026
Merged

JanProvaznik merged 2 commits into
dotnet:release/11.0.1xxfrom
JanProvaznik:backport/pr-56120-release-11.0.1xx

Conversation

@JanProvaznik

Copy link
Copy Markdown
Member

Backport of #56120 to release/11.0.1xx.

Cherry-picked the squash commit 6d10cf8ab0e932ec2efa5c74eb759ec75d06ae9c. This branch contains one commit on top of the release branch, without unrelated main history.

Release-specific adaptations

  • Apply MTP argument routing in MSBuildUtility, where that logic lives on the release branch, rather than adding main's extracted TestCommandOptions class. Preserve arguments after -- and add coverage for that boundary.
  • Retain the release branch's watch logging options. The combined logging/-mt regression uses --verbose; the unrelated main-only --trace feature is not backported.

Validation

  • CLI/MTP/run parser tests: 124 passed, one platform-specific skip.
  • Watch forwarding and file-discovery tests: 50 passed.

… argument (dotnet#56120)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 6d10cf8)
Copilot AI lite review requested due to automatic review settings September 9, 2026 16:00
@JanProvaznik
JanProvaznik requested review from a team, lbussell, mthalman and tmat as code owners September 9, 2026 16:00
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 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.

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.

🔵 Needs a closer look

It changes core CLI build/forwarding behavior (run/test/watch) and introduces a new MSBuild command-line assembly reference path, which warrants final human validation for servicing-branch safety.

Pull request overview

Backports the fix to ensure MSBuild build-engine -mt/-multithreaded switches are treated as MSBuild-only and forwarded to the underlying build invocation (instead of leaking to launched applications), including correct handling across -- boundaries and dotnet-watch file discovery.

Changes:

  • Extend MSBuild-only token separation (previously logger-focused) to also recognize -mt/-multithreaded and route these to MSBuild for dotnet run and dotnet test (MTP).
  • Update dotnet-watch argument handling to exclude MSBuild-only switches from positional file discovery while still forwarding them to the internal dotnet build invocation.
  • Factor the MSBuild command-line assembly reference logic into MSBuildRuntimeReference.targets and import it where needed; add regression coverage for quoting/response-file/-- cases.
File summaries
File Description
test/dotnet.Tests/LoggerUtilityTests.cs Adds coverage for recognizing -mt forms as MSBuild-only and preserves -- semantics for MTP.
test/dotnet.Tests/CommandTests/Run/RunParserTests.cs Validates dotnet run keeps -mt on the MSBuild side before -- and treats it as app args after --.
test/dotnet.Tests/CommandTests/Run/RunFileTests_BuildOptions.cs Adds end-to-end coverage for response files, env vars, and node-count behavior when -mt is used.
test/dotnet-watch.Tests/CommandLine/ProgramTests.GetProjectOptions.cs Ensures file-based entry point discovery isn’t broken when -mt precedes the file argument.
test/dotnet-watch.Tests/CommandLine/CommandLineOptionsTests.cs Adds watch forwarding/file-discovery coverage for -mt valid/invalid and -- boundary cases.
src/Dotnet.Watch/dotnet-watch/Program.cs Switches file discovery parsing to use the new filtered argument list.
src/Dotnet.Watch/dotnet-watch/CommandLine/CommandLineOptions.cs Filters MSBuild-only tokens (binlog + -mt) out of file-discovery args and forwards -mt to build args.
src/Cli/MSBuildRuntimeReference.targets New shared target/import providing MSBuild command-line assembly reference + package path validation.
src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj Replaces inlined MSBuild runtime reference logic with shared import.
src/Cli/Microsoft.DotNet.Cli.Definitions/Utilities/MSBuildArgumentParser.cs Adds centralized parsing for recognizing valid -mt/-multithreaded switch forms (incl. MSBuild-style quoting).
src/Cli/dotnet/LoggerUtility.cs Generalizes logger-only splitting into “MSBuild-only” splitting and includes -mt recognition.
src/Cli/dotnet/dotnet.csproj Imports shared MSBuild runtime reference targets so dotnet can use MSBuild command-line internals.
src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs Routes MSBuild-only tokens (incl. -mt) to MSBuild while preserving args after -- for the test app.
src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs Applies MSBuild -mt/node-count to in-process build parameters (managed-only).
src/Cli/dotnet/Commands/Run/RunCommand.cs Ensures MSBuild-only tokens don’t leak into application args for dotnet run.
src/Cli/dotnet/Commands/Publish/PublishCommand.cs Renames transformer arg to reflect generalized MSBuild-only splitting.
src/Cli/dotnet/Commands/Pack/PackCommand.cs Renames transformer arg to reflect generalized MSBuild-only splitting.
src/Cli/dotnet/Commands/DotNetCommandFactory.cs Uses generalized MSBuild-only splitting so -mt doesn’t interfere with file-based program routing.
src/Cli/AGENTS.md Documents the shared MSBuild command-line assembly reference mechanism and constraints.
Review details
  • Files reviewed: 19/19 changed files
  • Comments generated: 0
  • Review effort level: Lite

@JanProvaznik
JanProvaznik enabled auto-merge (squash) September 10, 2026 08:46
@JanProvaznik

Copy link
Copy Markdown
Member Author

checked offline that rc2 is not locked down, so removing the auto-applied servicing label

@JanProvaznik
JanProvaznik merged commit 572974c into dotnet:release/11.0.1xx Sep 10, 2026
23 of 24 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc2 milestone Sep 11, 2026
karolz-ms added a commit to microsoft/aspire that referenced this pull request Sep 24, 2026
## Description

Project Resource V2 makes the dashboard available earlier, but
coordinated project builds can delay full application readiness. .NET
SDK 11 RC1 introduces the `-mt` MSBuild switch, which allows supported
project builds to use multithreaded task execution.

This change:

- Detects the `dotnet` SDK selected for each build context, including
`global.json` selection and prerelease versions.
- Enables `-mt` for coordinated traversal builds and project rebuild
commands when the selected SDK supports the target:
  - Project and generated traversal builds use `11.0.100-rc.1` or newer.
- File-based `.cs` builds use `11.0.100-rtm.26473.104` or newer; stable
`11.0.100` and later are included.
- Uses the stricter file-based build floor because earlier .NET 11
prereleases lack both safe `-mt` argument forwarding and the
compiler-client mutex mitigation. The required fixes landed in
dotnet/sdk#56207, dotnet/roslyn#85675, and dotnet/dotnet#9565.
- Caches version probes by SDK-selection context and refreshes the
result when `global.json` changes.
- Reuses the same provider for existing file-based app and .NET tool SDK
validation.
- Omits `-mt` when version detection fails, preserving the existing
build behavior.

Validation:

- `.\restore.cmd`
- `./restore.sh`
- Affected `Aspire.Hosting` and `Aspire.Hosting.Dotnet` build completed
with zero warnings and errors.
- 47 focused provider, version-policy, coordinated-build, rebuild,
file-app, and .NET-tool tests passed.
- 15 focused `Aspire.Hosting.Tests` file-app SDK policy and
environment-aware provider cases passed.
- 6 focused `Aspire.Hosting.Dotnet.Tests` file-only build, rebuild,
mixed-model coordination, and configured rebuild argument cases passed.
- A repository-local .NET 11 RC1 `.csproj` build completed successfully
with `-mt`.
- A full `Aspire.Hosting.Tests` run encountered two unrelated
`MSBuildTests` timeouts in `dotnet build --disable-build-servers`; both
timeouts reproduced when retried in isolation.

Fixes #19944

## Checklist

- Is this feature complete?
  - [x] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] Yes
  - [ ] No
- Did you add public API?
  - [ ] Yes
    - If yes, did you have an API Review for it?
      - [ ] Yes
      - [ ] No
- Did you add `<remarks />` and `<code />` elements on your triple slash
comments?
      - [ ] Yes
      - [ ] No
  - [x] No
- Does the change make any security assumptions or guarantees?
  - [ ] Yes
    - If yes, have you done a threat model and had a security review?
      - [ ] Yes
      - [ ] No
  - [x] No

---------

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

This branch had an error being deployed

1 failed deployment
copilot-pat-pool — eb8b09cb Deployed Sep 10, 2026 by JanProvaznik via pre_activation #4043
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.

3 participants