Skip to content

Set apphost DOTNET_ROOT in InvokeTestingPlatform - #10413

Merged
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/fix-apphost-dotnet-root
Aug 3, 2026
Merged

Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/fix-apphost-dotnet-root

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Summary

  • derive DOTNET_ROOT_<ARCH> from DOTNET_HOST_PATH for compatible direct apphost launches
  • preserve explicit TestingPlatformEnvironmentVariable overrides, including clearing inherited higher-precedence roots when plain DOTNET_ROOT is supplied
  • add the TestingPlatformDisableAppHostDotnetRoot opt-out and cover automatic, override, opt-out, architecture, and Windows x86 behavior

Fixes #10408

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 55a4038e-bf34-484a-a7a8-e888ca0336db
Copilot AI review requested due to automatic review settings August 3, 2026 17:30
@Evangelink Amaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Aug 3, 2026
@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) August 3, 2026 17:33

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

Aligns direct apphost launches with dotnet test runtime resolution.

Changes:

  • Derives architecture-specific DOTNET_ROOT from DOTNET_HOST_PATH.
  • Preserves explicit overrides and adds an opt-out.
  • Adds unit, acceptance, and changelog coverage.
Show a summary per file
File Description
InvokeTestingPlatformTask.ToolResolution.cs Implements runtime-root selection and precedence.
InvokeTestingPlatformTask.Execution.cs Applies configuration before launch.
InvokeTestingPlatformTask.cs Adds the opt-out task property.
Microsoft.Testing.Platform.MSBuild.targets Exposes and passes the opt-out property.
InvokeTestingPlatformTaskTests.cs Tests core configuration behavior.
MSBuildTests.Test.cs Adds end-to-end apphost coverage.
Changelog-Platform.md Documents the behavior change.

Review details

  • Files reviewed: 7/7 changed files
  • Comments generated: 1
  • Review effort level: Balanced

@github-actions

This comment has been minimized.

@github-actions github-actions Bot 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.

Note

🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

Review Summary

This PR correctly implements DOTNET_ROOT_<ARCH> derivation from DOTNET_HOST_PATH for apphost launches in the InvokeTestingPlatform MSBuild target, matching dotnet test runtime resolution behavior. The implementation is well-structured with appropriate guard clauses and a clean opt-out mechanism.

✅ Strengths

  • Algorithmic correctness: The precedence logic (explicit arch-specific > explicit DOTNET_ROOT > derived) is sound. The Windows x86 special case correctly clears both DOTNET_ROOT_X86 and DOTNET_ROOT(x86) when only plain DOTNET_ROOT is supplied.
  • Public API surface: TestingPlatformDisableAppHostDotnetRoot is a simple bool property (no init accessor) — appropriate for an MSBuild task property. This project does not use PublicAPI.Unshipped.txt (no API compat validation configured), so no file update is needed.
  • Localization: The Log.LogMessage(MessageImportance.Low, ...) diagnostic string follows existing conventions in this project — other tasks use inline interpolated strings for diagnostic log messages rather than resx resources.
  • MSBuild authoring: The property default pattern (Condition=" '$(...)' == '' ") and task attribute wiring are idiomatic.
  • Test coverage: Unit tests cover the key scenarios (automatic, explicit override, opt-out, incompatible architecture, Windows x86 detection via [DataRow]). Integration test validates end-to-end behavior.
  • No init accessors on new public API ✅

💡 Minor observations (non-blocking)

  1. TryGetRunCommand() called in guard: This method is called here as a guard and will be called again later during base.Execute(). It appears inexpensive (property checks + file existence), so this is acceptable but worth noting for future readers.

  2. Test coverage gap for Windows x86 + explicit DOTNET_ROOT + explicit DOTNET_ROOT(x86): The unit test covers hasExplicitDotnetRoot=true but not the combined case where both DOTNET_ROOT and DOTNET_ROOT(x86) are explicitly set on a Windows x86 process (which should result in only clearing the arch-specific variable, not DOTNET_ROOT(x86)). This is a narrow edge case covered by the ternary logic but not explicitly tested. Non-blocking since the IsWindowsX86ProcessOn64BitOperatingSystem unit tests and the code path analysis confirm correctness.

Overall this is a clean, well-tested change. No blocking issues found.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🧪 Test quality grade — PR #10413

GradeTestMutationNotesHow to improve
A (90–100) new InvokeTestingPlatformTaskTests.
AddAppHostDotnetRootEnvironmentVariable_
AddsArchitectureSpecificVariableBeforeUserVariables
4/4 killed Equality + count + positional assertions kill all prepend, order, name, and value mutations. —
A (90–100) new InvokeTestingPlatformTaskTests.
AddAppHostDotnetRootEnvironmentVariable_
DoesNotOverrideExplicitArchitectureSpecificDotnetRoot
2/2 killed Count + value equality verify the early-exit no-op when arch var is already set. —
A (90–100) new InvokeTestingPlatformTaskTests.
AddAppHostDotnetRootEnvironmentVariable_
DoesNotOverrideExplicitDotnetRoot
3/3 killed Checks arch var is cleared and DOTNET_ROOT is preserved with exact values and count. —
A (90–100) new InvokeTestingPlatformTaskTests.
AddAppHostDotnetRootEnvironmentVariable_
DoesNothingForIncompatibleArchitecture
1/1 killed IsNull is the complete contract for the no-op path; kills any mutation that writes the variable. —
A (90–100) new InvokeTestingPlatformTaskTests.
AddAppHostDotnetRootEnvironmentVariable_
DoesNothingWhenDisabled
1/1 killed IsNull is the complete contract for the disable-flag no-op path. —
A (90–100) new InvokeTestingPlatformTaskTests.
AddAppHostDotnetRootEnvironmentVariable_
DoesNothingWithoutAppHost
1/1 killed IsNull is the complete contract when UseAppHost is false. —
A (90–100) new InvokeTestingPlatformTaskTests.
IsWindowsX86ProcessOn64BitOperatingSystem_
ReturnsExpectedResult
4/4 killed Four DataRows isolate each Boolean factor; truth-table coverage kills all single-flag mutations. —
A (90–100) new MSBuildTests.
InvokeTestingPlatform_
Target_
Should_
Set_
DotnetRoot_
For_
AppHost
3/3 killed Three end-to-end process runs verify derived, explicit-override, and disabled paths with exact output. —

This advisory comment was generated automatically. Grades are heuristic and informational — they do not block merging. Re-run with /grade-tests.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 · 74.5 AIC · ⌖ 4.47 AIC · ⊞ 11.8K · [◷]( · ◷)

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 55a4038e-bf34-484a-a7a8-e888ca0336db
Copilot AI review requested due to automatic review settings August 3, 2026 18:14

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.

Review details

  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🧵 Parallel-safety audit — PR #10413

Parallelization — one row per test assembly audited:

Test assembly Scope Workers Analyzer coverage
Microsoft.Testing.Platform.MSBuild.UnitTests MethodLevel CPU count (Workers = 0) Coverable once the parallel-safety analyzers ship (assembly attribute opt-in)
Microsoft.Testing.Platform.Acceptance.IntegrationTests MethodLevel CPU count (Workers = 0) Coverable once the parallel-safety analyzers ship (assembly attribute opt-in)

Findings: A (global-state) 0 · B (paths) 0 · C (declaration) 0 · D (over-serialization) 0 — by severity: Critical 0 · High 0 · Warning 0 · Info 0.


Nothing audited here touches process-global state, shared filesystem paths, or [ResourceLock] / [DoNotParallelize] declarations. Nothing to flag for parallel-safety.

Why each new test is safe:

  • InvokeTestingPlatformTaskTests.cs (new unit tests): The AppHostTaskFixture creates a unique temp directory via Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")) — distinct per fixture instance, cleaned up in Dispose(). Tests call task.InvokeAddAppHostDotnetRootEnvironmentVariable() which mutates task.EnvironmentVariables (an instance property on a per-test object), never System.Environment.SetEnvironmentVariable. No process-global state is touched.

  • MSBuildTests.Test.cs (new acceptance test): TestAsset.GenerateAssetAsync creates a unique directory via TempDirectory.CreateUniqueDirectory (uses RandomId.Next()), so the test asset path never collides across concurrent tests. The Dictionary<string, string?> passed as environmentVariables is forwarded to child-process ProcessStartInfo.Environment — it does not call System.Environment.SetEnvironmentVariable on the test host process. Path.GetTempPath() is used purely as a value in that dictionary, not for test-host-level I/O.

Advisory only — heuristic, non-blocking. Re-run with /parallel-audit. This audit answers "is it parallel-safe?"; for testability, smells, or flakiness see the detect-static-dependencies / test-smell-detection / test-anti-patterns analyses.

🤖 Automated content by GitHub Copilot. Generated by the Parallel-safety audit on PR (on open / sync) workflow. · sonnet46 · 78.9 AIC · ⌖ 4.25 AIC · ⊞ 18K · [◷]( · ◷)

@github-actions github-actions Bot 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.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 · 104.2 AIC · ⌖ 4.67 AIC · ⊞ 11.8K · ◷

@Evangelink
Amaury Levé (Evangelink) merged commit c10ff43 into main Aug 3, 2026
54 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/fix-apphost-dotnet-root branch August 3, 2026 19:39
@ViktorHofer

Copy link
Copy Markdown
Member

Amaury Levé (@Evangelink) can I already start using this feature? Which feed do you publish to?

@Evangelink

Copy link
Copy Markdown
Member Author

Amaury Levé (@Evangelink) can I already start using this feature? Which feed do you publish to?

Abosolutely! It's published to test-tools feed (more info at https://github.com/microsoft/testfx/blob/main/docs/preview.md#early-access-to-mstest-packages)

Viktor Hofer (ViktorHofer) added a commit to dotnet/dotnet that referenced this pull request Aug 4, 2026
…OOT workaround

microsoft/testfx#10413 makes InvokeTestingPlatformTask configure DOTNET_ROOT
for app host launches automatically, so the inline task that set the variable
on the MSBuild process is no longer needed.

That fix isn't on the regular feeds yet, so pick it up from the testfx
test-tools preview channel (https://aka.ms/mstest/preview) by overriding the
Arcade default for MicrosoftTestingPlatformVersion. Both can be reverted once
a release containing the fix flows to the regular feeds.

Verified that the test applications still run against the repo-local .NET
installation with no DOTNET_ROOT set in the environment.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 761287f0-d9eb-4740-974e-b168dab091a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvokeTestingPlatform should set DOTNET_ROOT_&lt;ARCH&gt; for the apphost, like the SDK does for dotnet test

4 participants