Skip to content

Preserve invocation context during MTP strict-MT preparation - #56909

Merged
Evangelink merged 1 commit into
mainfrom
dev/amauryleve/main-mtp-cwd-fixes
Nov 3, 2026
Merged

Evangelink merged 1 commit into
mainfrom
dev/amauryleve/main-mtp-cwd-fixes

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Strict-MT MTP preparation owns the process current directory until its MSBuild session ends. Parent-side operations must retain the invocation directory: otherwise background workload updates can miss repository global.json and NuGet.Config, and relative DOTNET_CLI_TEST_TRACEFILE paths can produce caught I/O exceptions and MSB4287 while dotnet test exits successfully without the requested trace.

Capture the invocation directory before scheduling background updates and forward it through workload manifest discovery and the existing NuGet downloader override. Normalize and cache the trace path before managed MTP preparation starts. This preserves main's public CommandServices constructor contract, file-based execution, and strict-MT directory ownership without disabling updates or weakening MSBuild checks.

Follow-up to #56893. The matching release backport is #56908.

Validation

  • Managed CLI, shared-AOT compilation, and test builds passed with zero warnings or errors. Native publishing and native execution were not run.
  • 75 focused cases passed, 0 failed, 0 skipped, including workload configuration/local-feed lookup, trace logging, main's file-based no-build MT/legacy paths, CommandServices propagation, preparation failures, and multi-project/multi-TFM binlogs.
  • The actual built SDK reproduced the baseline strict-MT relative-path failure: exit 0, 10 caught I/O exceptions, MSB4287, and no requested trace. After the fix, strict-MT relative, strict-MT absolute, legacy relative, and disabled-logging controls all exit 0 without those errors; enabled traces contain project-loading and test-process events.
  • Current dotnet.dll and Microsoft.DotNet.Cli.Utils.dll were explicitly deployed into the redist layout, with matching SHA-256 hashes confirmed before and after the test runner.

Windows win-x64; built SDK 12.0.100-dev, runtime 12.0.0-alpha.1.26528.111, MSBuild 18.13.0-1.26528.111, MTP 2.6.0-preview.26531.5, and MSTest 4.6.0-preview.26531.5. Bootstrap SDK: 12.0.100-alpha.1.26480.102.

Exact commands and retained local diagnostics
.\eng\build.ps1 -c Debug /p:PublishAot=false /p:_ShouldPublishDotnetAot=false /bl:artifacts\log\Debug\mtp-cwd-main-baseline.binlog
.\.dotnet\dotnet.exe build src\Cli\dotnet\dotnet.csproj -c Debug --nologo -v:quiet -bl:artifacts\log\Debug\mtp-cwd-main-fixed-managed-build.binlog
.\.dotnet\dotnet.exe build src\Cli\dotnet-aot\dotnet-aot.csproj -c Debug --nologo -v:quiet -bl:artifacts\log\Debug\mtp-cwd-main-fixed-shared-aot-build.binlog /p:PublishAot=false
.\.dotnet\dotnet.exe build test\dotnet.Tests\dotnet.Tests.csproj -c Debug --nologo -v:quiet -bl:artifacts\log\Debug\mtp-cwd-main-fixed-tests-build.binlog --framework net12.0
.\.dotnet\dotnet.exe scripts\RunTests.cs -- --project test\dotnet.Tests\dotnet.Tests.csproj --framework net12.0 --filter "FullyQualifiedName~GivenDotnetTestProducesBinaryLog|FullyQualifiedName~NuGetPackageDownloaderTests|FullyQualifiedName~GivenWorkloadManifestUpdater|FullyQualifiedName~GivenDotnetTestRunsFileBasedApps.RunWithNoBuildHonorsMultiThreading|FullyQualifiedName~GivenCommandServices" --test-binlogs

All commands exited 0. Runs used a process-local bounded PATH, DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=0, MSBUILDUSESERVER=0, and MSBUILDDISABLENODEREUSE=1; user settings were not changed.

Retained locally:

  • TRX and runner build binlog: artifacts\log\test-runs\dotnet.Tests\20261103-112921-40944\test-results.trx and build.binlog.
  • Concrete baseline/fixed product commands, exit codes, trace paths, and output/binlog paths: artifacts\log\Debug\mtp-cwd-main-baseline-product-results.json and mtp-cwd-main-fixed-product-results.json.
  • Full test transcript: artifacts\log\Debug\mtp-cwd-main-fixed-focused-runner.log.

Keep background workload global.json and NuGet configuration anchored to the captured invocation directory, and initialize absolute diagnostic trace paths before strict MT owns the process directory. Preserve the existing public restoring-command constructor and add configuration and real-product trace regressions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 3, 2026 12:52
@Evangelink
Evangelink requested review from a team, lbussell and mthalman as code owners November 3, 2026 12:52
@azure-pipelines

Copy link
Copy Markdown
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.

@Evangelink

Copy link
Copy Markdown
Member Author

/azp run dotnet-sdk-public-ci

@azure-pipelines

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

@Evangelink
Evangelink enabled auto-merge (squash) November 3, 2026 13:01

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 remain for the changes preserving invocation-directory behavior during MTP preparation.

No open issues 🎉

What changed in this PR

This follow-up to #56893 preserves the invocation directory for parent-process operations during Microsoft Testing Platform (MTP) strict-MT preparation, without changing MSBuild’s directory ownership or the public RestoringCommand constructor contract.

Changes:

  • Pass the captured directory through background workload updates for repository-local global.json and NuGet configuration lookup.
  • Resolve and cache absolute trace paths before strict-MT preparation begins.
  • Add workload and trace regressions, including file-based execution, and document the directory invariant.
File Description
test/​dotnet.Tests/​NuGetPackageDownloaderTests.cs Tests captured-directory workload configuration and local-feed lookup.
test/​dotnet.Tests/​CommandTests/​Test/​GivenDotnetTestRunsFileBasedApps.cs Adds trace assertions to file-based no-build coverage.
test/​dotnet.Tests/​CommandTests/​Test/​GivenDotnetTestProducesBinaryLog.cs Tests relative and absolute trace paths across preparation modes.
src/​Cli/​dotnet/​NugetPackageDownloader/​NuGetPackageDownloader.cs Forwards a directory override through the workload downloader factory.
src/​Cli/​dotnet/​Commands/​Workload/​Install/​WorkloadManifestUpdater.cs Uses the captured directory for workload and NuGet configuration.
src/​Cli/​dotnet/​Commands/​Test/​MTP/​MSBuildUtility.cs Passes the session’s invocation directory to RestoringCommand.
src/​Cli/​dotnet/​Commands/​Test/​MTP/​MicrosoftTestingPlatformTestCommand.cs Initializes trace logging before managed preparation starts.
src/​Cli/​dotnet/​Commands/​Test/​MTP/​Logger.cs Normalizes and caches the absolute trace path.
src/​Cli/​dotnet/​Commands/​Restore/​RestoringCommand.cs Captures the directory before scheduling background updates.
src/​Cli/​AGENTS.md Documents parent-process invocation-directory requirements.

Review effort: Balanced

@Evangelink
Evangelink merged commit da21c02 into main Nov 3, 2026
28 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/main-mtp-cwd-fixes branch November 3, 2026 15:26
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.

4 participants