Repository navigation
Allow passing environment variables to the test process from the InvokeTestingPlatform target - #10405
Conversation
There was a problem hiding this comment.
Pull request overview
Adds MSBuild support for passing environment variables to MTP test processes.
Changes:
- Adds item- and property-based environment-variable configuration.
- Projects configured values onto
ToolTask.EnvironmentVariables. - Adds unit, acceptance, and changelog coverage.
Show a summary per file
| File | Description |
|---|---|
InvokeTestingPlatformTaskTests.cs |
Tests environment-variable projection and edge cases. |
MSBuildTests.Test.cs |
Verifies variables reach the test process. |
InvokeTestingPlatformTask.Execution.cs |
Converts and applies environment-variable items. |
InvokeTestingPlatformTask.cs |
Adds the task input parameter and metadata definition. |
Microsoft.Testing.Platform.MSBuild.targets |
Exposes item and property configuration to MSBuild users. |
Changelog-Platform.md |
Documents the new capability. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 0
- Review effort level: Balanced
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
Summary
Clean, well-documented change with good test coverage. One blocking typo prevents the property-based sugar from working at all.
Critical Issue
Typo in .targets file — Include="$(TestingPlatformEnvironmentVariable)" (singular) should be Include="$(TestingPlatformEnvironmentVariables)" (plural). The condition checks the plural property but the Include reads a different (empty) symbol, so the property sugar path is dead code. See inline comment.
Dimension Verdict
| # | Dimension | Verdict |
|---|---|---|
| 1 | Algorithmic Correctness | ❌ Typo breaks property→item folding |
| 2 | Threading & Concurrency | ✅ N/A |
| 3 | Security & IPC | ✅ OK |
| 4 | Public API & Binary Compat | ✅ New property, additive only |
| 5 | Performance | ✅ Negligible allocations at task startup |
| 6 | Cross-TFM | ✅ IndexOf(char) / Substring are available everywhere |
| 7 | Resource / IDisposable | ✅ N/A |
| 8 | Defensive Coding | ✅ Null/empty guards present |
| 9 | Localization | ✅ N/A (no user-facing strings) |
| 10 | Test Isolation | ✅ Unit tests use in-memory items |
| 11 | Test Quality | ✅ Good edge-case coverage (semicolons, whitespace, empty) |
| 12 | Error Handling | ✅ Graceful null return for blank names |
| 13 | Naming | ✅ Consistent with existing conventions |
| 14 | Code Style | ✅ Follows repo conventions |
| 15 | Documentation | ✅ XML docs and inline comments clear |
| 16 | Changelog | ✅ Entry added |
| 17 | MSBuild Targets | ❌ Singular/plural typo (see above) |
| 18 | Test Asset Coverage | ✅ Both item and property paths exercised |
| 19 | Backward Compat | ✅ Null EnvironmentVariables preserved when nothing set |
| 20 | IPC Contract | ✅ N/A |
| 21 | Memory Safety | ✅ N/A |
| 22 | Platform-Specific |
Please fix the singular→plural typo and the integration test should then pass the property path end-to-end.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 66.4 AIC · ⌖ 4.7 AIC · ⊞ 11.8K · ◷
…stingPlatform
`InvokeTestingPlatformTask` derives from `ToolTask` and therefore already inherits a
functional `EnvironmentVariables` parameter, but the `InvokeTestingPlatform` target
never plumbed anything into it. There was no supported way to set an environment
variable for the test process from MSBuild, which matters because MTP launches the
apphost directly and an apphost ignores `PATH`: repos using a repo-local SDK had no
way to point the test run at it.
Bind the inherited parameter from a new `TestingPlatformEnvironmentVariable` item:
<TestingPlatformEnvironmentVariable Include="DOTNET_ROOT" Value="$(DotNetRoot)" />
An item rather than a property, because item metadata is not subject to MSBuild's
`;` splitting, so a value containing a `;` reaches the test process exactly as
authored. `ToolTask` applies the variables on top of the environment inherited from
the MSBuild process, and declaring no item leaves that environment untouched, so the
change is fully backwards compatible.
No task code is needed: the item is transformed into the `NAME=VALUE` shape
`ToolTask.EnvironmentVariables` expects directly in the target.
Fixes #10342
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3369b9ec-a09b-4371-882d-7a2e67ebbf17
a46e1b3 to
4fe932d
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 82.3 AIC · ⌖ 4.19 AIC · ⊞ 11.8K · ◷
Amaury Levé (Evangelink)
left a comment
There was a problem hiding this comment.
I reviewed the current simplified implementation at 4fe932d. The item transform preserves semicolon-containing values and binds directly to ToolTask.EnvironmentVariables; inherited-environment behavior, cross-platform behavior, and backward compatibility look sound. The acceptance test validates values in the actual test process, and the changelog matches the supported contract. Approving with one non-blocking suggestion to add inheritance and override coverage.
…ronment The acceptance test only proved that declared TestingPlatformEnvironmentVariable items reach the test process. It did not pin the load-bearing half of the feature: that ToolTask layers EnvironmentVariables on top of the environment inherited from MSBuild rather than replacing it. Under replace semantics, declaring a single variable would strip PATH / DOTNET_ROOT / ... from every test process. Set a variable on the MSBuild process that is deliberately not declared as an item and assert it still reaches the test process alongside the declared values. Co-authored-by: Copilot <[email protected]> Copilot-Session: 3369b9ec-a09b-4371-882d-7a2e67ebbf17
🧪 Test quality grade — PR #10405
This advisory comment was generated automatically. Grades are heuristic
|
addressed
Fixes #10342
Summary
InvokeTestingPlatformTaskderives fromToolTaskand therefore already inherits a functionalEnvironmentVariablesparameter, but theInvokeTestingPlatformtarget never plumbed anything into it — so there was no supported way to set an environment variable for the test process from MSBuild.This matters because MTP launches the apphost directly and an apphost ignores
PATH: it resolves a runtime throughDOTNET_ROOT, then falls back to the machine-wide install. Repos that build against a repo-local SDK (.dotnet/) and run tests through/t:Testtherefore silently run on the wrong runtime, or fail outright on a machine with no .NET installed.Shape
An item, not a property: item metadata is not subject to MSBuild's
;splitting, so a value containing a;reaches the test process exactly as authored. (Astring[]property would bindMY_PATHS=/a;/bas["MY_PATHS=/a", "/b"].)No task code is needed. The item is transformed into the
NAME=VALUEshape the inheritedToolTask.EnvironmentVariablesparameter expects, directly in the target:Verified that the transform is not re-split on
;: it produces exactly one item per declaration, withMY_PATHS=/a;/bintact.ToolTaskapplies these on top of the environment inherited from the MSBuild process, and declaring no item leaves that environment untouched — so the change is fully backwards compatible.Scope
This is only the passthrough half of #10342. The separate proposal to have the task set
DOTNET_ROOT_<ARCH>itself (mirroring what the SDK does fordotnet test) is intentionally not included here — it is a behavior change that needs its own opt-out and tests.Testing
New acceptance test
InvokeTestingPlatform_Target_Should_Pass_EnvironmentVariables_To_TestProcessrunsbuild -t:Testwith two declared variables and asserts on what the test process actually observed, including a value containing a;.Verified end-to-end locally against the packed
Microsoft.Testing.Platform.MSBuildpackage:and, with no item declared, the ambient value still flows through by inheritance and the build stays warning-free:
Note: a full
-packcould not run on this machine (theuap10.0.16299projects require desktop MSBuild), so the acceptance test itself is validated in CI.