Skip to content

Honor MSBuild -mt in MTP test preparation - #56893

Merged
Evangelink merged 1 commit into
mainfrom
dev/amauryleve/mtp-msbuild-threading
Nov 3, 2026
Merged

Evangelink merged 1 commit into
mainfrom
dev/amauryleve/mtp-msbuild-threading

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Related to #56837.

MTP has the same preparation gap: dotnet test -mt forwards the switch to its main build, but the shared MSBuildSession never applies it to BuildParameters. Restore, device discovery, deployment, and ComputeRunArguments therefore ignore explicit MT settings, including --no-build preparation.

Apply recognized explicit switches using MSBuild's existing parser and environment precedence. Preserve the single-node limit, target-produced project state, and one coherent preparation binlog; do not add response-file discovery or depend on the unmerged run-command PR.

A flag-only fix is insufficient for MTP's long-lived session. The bundled engine's strict-mode scope owns the process current directory until EndBuild and permits only one active strict build per process. Restoring CWD between requests causes MSB4286; interleaving another in-process build causes MSB4289. Keep MT's CWD ownership intact and run intervening build/restore operations out-of-process at the captured invocation directory. Existing execution policy is unchanged when no MT preparation session is active, and relative arguments/log paths keep their original meaning.

Add real-product regressions for aliases, quoted/empty values, duplicate precedence, environment overrides, per-target execution mode, relative project paths, device listing, file-based --no-build, multi-project/multi-TFM binlogs, and restore/build/deployment/run-argument failures. Update CLI contributor guidance with the session invariant.

Validation

Windows x64, built SDK 12.0.100-dev, bootstrap SDK 12.0.100-alpha.1.26480.102, bundled Microsoft.Build 18.13.0-1.26528.111, and MTP 2.6.0-preview.26531.5. No dependency versions changed.

  • Focused dotnet.Tests: 169 passed, 0 failed, 0 skipped. These execute the assembled SDK and assert actual target working directories, module results, exit codes, log placement, and binlog structure.
  • Microsoft.DotNet.Cli.Utils.Tests: 236 passed, 0 failed, 7 existing platform/issue skips.
  • Managed CLI and the dotnet-aot.csproj managed/shared-source compilation passed without warnings.
  • Native publishing was not validated: the default Windows build encounters the missing C++ platform linker in the installer finalizer. The managed redist was assembled with native publishing disabled; no product feature flags or strict-mode checks were disabled.

Commands used for the final validation:

$env:DOTNET_ADD_GLOBAL_TOOLS_TO_PATH = '0'
.\eng\build.ps1 -c Debug /p:PublishAot=false /p:_ShouldPublishDotnetAot=false /bl:artifacts\log\Debug\managed-baseline.binlog
.\.dotnet\dotnet.exe build src\Cli\dotnet\dotnet.csproj -c Debug --nologo -v:minimal -bl:artifacts\log\Debug\mtp-mt-lifecycle.binlog
Copy-Item artifacts\bin\Microsoft.DotNet.Cli.Utils\Debug\net12.0\Microsoft.DotNet.Cli.Utils.dll artifacts\bin\redist\Debug\dotnet\sdk\12.0.100-dev\Microsoft.DotNet.Cli.Utils.dll
.\.dotnet\dotnet.exe scripts\RunTests.cs -- --project test\dotnet.Tests\dotnet.Tests.csproj --filter 'FullyQualifiedName~GivenDotnetTestProducesBinaryLog|FullyQualifiedName~GivenDotnetTestRunsFileBasedApps|FullyQualifiedName~LoggerUtilityTests|FullyQualifiedName~GivenCommandServices|FullyQualifiedName~DotnetMsbuildInProcTests|FullyQualifiedName~GivenDotnetTestSelectsDevice.ItFailsWhen'
.\.dotnet\dotnet.exe scripts\RunTests.cs -- --project test\Microsoft.DotNet.Cli.Utils.Tests\Microsoft.DotNet.Cli.Utils.Tests.csproj
.\.dotnet\dotnet.exe build src\Cli\dotnet-aot\dotnet-aot.csproj -c Debug --nologo -v:minimal -bl:artifacts\log\Debug\mtp-mt-aot-managed.binlog

All commands above exited 0. TRX and build binlogs are retained under artifacts\log\test-runs\dotnet.Tests\20261102-093421-154276 and artifacts\log\test-runs\Microsoft.DotNet.Cli.Utils.Tests\20261102-095013-255352.

Preserve strict MT working-directory ownership and isolate interleaved build/restore operations while retaining the shared preparation binlog.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 10:03
@Evangelink
Evangelink requested review from a team, lbussell and mthalman as code owners November 2, 2026 10:03
@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.

🟢 Approval recommended

No active review issues block approval of the MTP preparation changes.

No open issues 🎉

What changed in this PR

This PR makes Microsoft.Testing.Platform (MTP) preparation honor MSBuild’s explicit -mt settings and environment precedence, including --no-build, while preserving the shared preparation session and binlog.

Changes:

  • Applies multithreading settings to preparation without adding automatic response-file discovery.
  • Preserves strict-mode working-directory ownership by running intervening builds and restores out-of-process at the captured invocation directory.
  • Adds regression coverage for switch precedence, device operations, file-based apps, failures, and binlogs, and documents the session invariant.
File Description
test/​dotnet.Tests/​CommandTests/​Test/​GivenDotnetTestSelectsDevice.cs Covers deployment and run-argument failures with MT enabled and disabled.
test/​dotnet.Tests/​CommandTests/​Test/​GivenDotnetTestRunsFileBasedApps.cs Verifies MT preparation for file-based --no-build runs.
test/​dotnet.Tests/​CommandTests/​Test/​GivenDotnetTestProducesBinaryLog.cs Tests switch precedence, preparation execution mode, failures, and coherent binlogs.
src/​Cli/​Microsoft.DotNet.Cli.Utils/​MSBuildForwardingAppWithoutLogging.cs Supports out-of-process execution in a specified working directory.
src/​Cli/​dotnet/​MSBuildSession.cs Applies MT settings and preserves strict-mode directory ownership.
src/​Cli/​dotnet/​Commands/​Test/​MTP/​MSBuildUtility.cs Resolves input paths and routes intervening builds through session-aware execution.
src/​Cli/​dotnet/​Commands/​Restore/​RestoringCommand.cs Propagates out-of-process execution to separate restore and main build operations.
src/​Cli/​dotnet/​Commands/​MSBuild/​MSBuildForwardingApp.cs Exposes working-directory-aware out-of-process forwarding.
src/​Cli/​AGENTS.md Documents MTP preparation lifecycle and regression requirements.

Review effort: Balanced

@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.

overall reasonable

should we get this also for release/11.0.2xx branch ?

@Evangelink
Evangelink merged commit 2f0da07 into main Nov 3, 2026
28 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/mtp-msbuild-threading branch November 3, 2026 09:26
@Evangelink

Copy link
Copy Markdown
Member Author

/backport to release/11.0.1xx

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0.1xx (link to workflow run)

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@Evangelink backporting to release/11.0.1xx failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick 2f0da079350a63d165b990e0cbfb3ead6bd09a58

Auto-merging src/Cli/AGENTS.md
CONFLICT (content): Merge conflict in src/Cli/AGENTS.md
Auto-merging src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs
CONFLICT (content): Merge conflict in src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs
Auto-merging src/Cli/dotnet/Commands/MSBuild/MSBuildForwardingApp.cs
Auto-merging src/Cli/dotnet/Commands/Restore/RestoringCommand.cs
Auto-merging src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
CONFLICT (content): Merge conflict in src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
Auto-merging src/Cli/dotnet/MSBuildSession.cs
Auto-merging test/dotnet.Tests/CommandTests/Test/GivenDotnetTestProducesBinaryLog.cs
CONFLICT (modify/delete): test/dotnet.Tests/CommandTests/Test/GivenDotnetTestRunsFileBasedApps.cs deleted in HEAD and modified in 2f0da07935 (Honor MSBuild -mt in MTP test preparation (#56893)).  Version 2f0da07935 (Honor MSBuild -mt in MTP test preparation (#56893)) of test/dotnet.Tests/CommandTests/Test/GivenDotnetTestRunsFileBasedApps.cs left in tree.
Auto-merging test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.cs
error: could not apply 2f0da07935... Honor MSBuild -mt in MTP test preparation (#56893)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Honor MSBuild -mt in MTP test preparation
Using index info to reconstruct a base tree...
M	src/Cli/AGENTS.md
M	src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs
M	src/Cli/dotnet/Commands/MSBuild/MSBuildForwardingApp.cs
M	src/Cli/dotnet/Commands/Restore/RestoringCommand.cs
M	src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
M	src/Cli/dotnet/MSBuildSession.cs
M	test/dotnet.Tests/CommandTests/Test/GivenDotnetTestProducesBinaryLog.cs
A	test/dotnet.Tests/CommandTests/Test/GivenDotnetTestRunsFileBasedApps.cs
M	test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Cli/AGENTS.md
CONFLICT (content): Merge conflict in src/Cli/AGENTS.md
Auto-merging src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs
CONFLICT (content): Merge conflict in src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs
Auto-merging src/Cli/dotnet/Commands/MSBuild/MSBuildForwardingApp.cs
Auto-merging src/Cli/dotnet/Commands/Restore/RestoringCommand.cs
Auto-merging src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
CONFLICT (content): Merge conflict in src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
Auto-merging src/Cli/dotnet/MSBuildSession.cs
Auto-merging test/dotnet.Tests/CommandTests/Test/GivenDotnetTestProducesBinaryLog.cs
CONFLICT (modify/delete): test/dotnet.Tests/CommandTests/Test/GivenDotnetTestRunsFileBasedApps.cs deleted in HEAD and modified in Honor MSBuild -mt in MTP test preparation.  Version Honor MSBuild -mt in MTP test preparation of test/dotnet.Tests/CommandTests/Test/GivenDotnetTestRunsFileBasedApps.cs left in tree.
Auto-merging test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Honor MSBuild -mt in MTP test preparation
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

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