Repository navigation
Honor requested test architectures - #17143
Conversation
Make VSTest and xUnit select the requested architecture, validate fixed-host runners before execution, and defer architecture inference until the SDK has finalized .NET Framework platform settings. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
Honor resolved apphost RIDs, preserve custom run commands, select matching framework-dependent hosts, validate fixed .NET Framework executables, and add behavioral MSBuild coverage. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
There was a problem hiding this comment.
Pull request overview
This PR updates Arcade SDK test infrastructure to honor TestArchitectures by selecting architecture-appropriate test hosts (or failing fast when that isn’t possible), and adds documentation + regression tests to lock in the new behavior. This aligns the reported test environment with the actual host architecture and prevents misleading “x86”/“x64” result naming when the same host is reused.
Changes:
- Defer
TestArchitecturesinitialization until execution time and infer the “built” (host/apphost) architecture, then validate requested-vs-built mismatches for fixed-host runners. - Pass the requested architecture through to VSTest (
dotnet test --arch ...) and select architecture-specificdotnethosts for framework-dependent xUnit, xUnit v3, and Microsoft.Testing.Platform when applicable. - Add MSBuild structural + execution-level tests and update documentation to describe runner-specific architecture behavior/constraints.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.DotNet.Arcade.Sdk/tools/XUnitV3/XUnitV3.Runner.targets | Opts into architecture mismatch validation and selects an architecture-specific dotnet host for default dotnet runs. |
| src/Microsoft.DotNet.Arcade.Sdk/tools/XUnit/XUnit.Runner.targets | Selects architecture-specific dotnet host for Core xUnit runs and adds validation/erroring for unsupported arch scenarios. |
| src/Microsoft.DotNet.Arcade.Sdk/tools/VSTest.targets | Passes requested architecture into dotnet test via --arch. |
| src/Microsoft.DotNet.Arcade.Sdk/tools/Tests.targets | Defers TestArchitectures initialization, computes built/default architectures, and adds mismatch validation for fixed-host runners. |
| src/Microsoft.DotNet.Arcade.Sdk/tools/Microsoft.Testing.Platform/Microsoft.Testing.Platform.targets | Opts into architecture mismatch validation and selects an architecture-specific dotnet host for default dotnet runs. |
| src/Microsoft.DotNet.Arcade.Sdk.Tests/TestArchitecturesTests.cs | Adds regression tests validating target file structure and one execution-level behavior for apphost-driven defaults. |
| Documentation/ArcadeSdk.md | Documents updated TestArchitectures defaults and runner-specific limitations/expectations. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 7/7 changed files
- Comments generated: 4
Use architecture-generic mismatch guidance and distinguish unknown host roots from missing architecture-specific dotnet installations. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
Ensure the test project collection releases loaded project state and file handles even when the behavioral assertion fails. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (3)
src/Microsoft.DotNet.Arcade.Sdk/tools/XUnitV3/XUnitV3.Runner.targets:32
$(_ArchitectureSpecificDotNetTool)is only assigned when$(_DotNetHostRoot)is non-empty. Since MSBuild properties persist across batched target invocations, a previous batch can leave a stale value here, causing the later mismatch errors to report the wrong state (e.g., skipping the “path cannot be determined” case). Initialize the property to empty before the conditional assignment so each batch computes it deterministically.
<_DotNetExecutableName>$([System.IO.Path]::GetFileName('$(DotNetTool)'))</_DotNetExecutableName>
<_ArchitectureSpecificDotNetTool Condition="'$(_DotNetHostRoot)' != ''">$([System.IO.Path]::Combine('$(_DotNetHostRoot)', '$(_TestArchitecture)', '$(_DotNetExecutableName)'))</_ArchitectureSpecificDotNetTool>
src/Microsoft.DotNet.Arcade.Sdk/tools/Microsoft.Testing.Platform/Microsoft.Testing.Platform.targets:20
$(_ArchitectureSpecificDotNetTool)is set conditionally, but MSBuild properties can carry over between batchedRunTestsexecutions. If$(_DotNetHostRoot)is empty for a later batch, the property can retain a previous non-empty value and trigger the wrong error path. Reset it to empty before the conditional assignment.
<_DotNetExecutableName>$([System.IO.Path]::GetFileName('$(DotNetTool)'))</_DotNetExecutableName>
<_ArchitectureSpecificDotNetTool Condition="'$(_DotNetHostRoot)' != ''">$([System.IO.Path]::Combine('$(_DotNetHostRoot)', '$(_TestArchitecture)', '$(_DotNetExecutableName)'))</_ArchitectureSpecificDotNetTool>
src/Microsoft.DotNet.Arcade.Sdk/tools/XUnit/XUnit.Runner.targets:34
$(_ArchitectureSpecificDotNetTool)is only assigned when$(_DotNetHostRoot)is non-empty. BecauseRunTestsis batched over@(TestToRun)and MSBuild properties persist across batches, a stale value can carry over and make the host-selection and error conditions behave incorrectly. Clear it before the conditional assignment (similar to how_TestRunneris explicitly reset).
<_DotNetExecutableName>$([System.IO.Path]::GetFileName('$(DotNetTool)'))</_DotNetExecutableName>
<_ArchitectureSpecificDotNetTool Condition="'$(_DotNetHostRoot)' != ''">$([System.IO.Path]::Combine('$(_DotNetHostRoot)', '$(_TestArchitecture)', '$(_DotNetExecutableName)'))</_ArchitectureSpecificDotNetTool>
- Files reviewed: 7/7 changed files
- Comments generated: 0 new
Copy the exact Arcade SDK targets inspected by TestArchitecturesTests into the test payload so the tests do not depend on a repository checkout in Helix. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
|
CI investigation result: this was PR-related, not flaky. Both failed builds (#1515428 and #1517435) consistently failed Fixed in |
Default non-apphost .NET Core tests to DotNetToolArchitecture regardless of RuntimeIdentifier or PlatformTarget, with behavioral coverage for the documented contract. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
Summary
TestArchitecturesinitialization until the SDK has finalized .NET Framework platform settings and infer the actual apphost ordotnethost architectureFixes #16003
Validation
Build.cmd -test -projects src\Microsoft.DotNet.Arcade.Sdk.Tests\Microsoft.DotNet.Arcade.Sdk.Tests.csproj -configuration DebugBuild.cmd -configuration Release -test