Repository navigation
[release/11.0.1xx] Fix dotnet test device discovery for multi-targeted projects - #56170
Merged
jonathanpeppers merged 1 commit intoSep 9, 2026
Conversation
## Summary Fixes `dotnet test` device discovery for multi-targeted Microsoft.Testing.Platform projects when workload-provided device targets are imported only by target-framework-specific inner builds. This is the project shape produced by the experimental MAUI testing template in [dotnet/maui-labs#444](dotnet/maui-labs#444). Its [`MauiTest1.csproj` uses `TargetFrameworks` for Android, iOS, and Mac Catalyst](https://github.com/dotnet/maui-labs/blob/28f1052493060c6d3c123613e03e94f3ad61d627/src/Testing/templates/mauitest/MauiTest1.csproj#L3-L5). ## Problem For a project that declares `TargetFrameworks`, `dotnet test` first evaluates the outer cross-targeting project. Workload-specific targets such as Android's `ComputeAvailableDevices` are not imported into that outer evaluation; they become available only after `TargetFramework` is set for an inner build. The existing pre-build device-selection logic checked the outer project's target table and returned early when `ComputeAvailableDevices` was absent. As a result, plain `dotnet test` skipped device selection and continued into Android deployment without setting `$(Device)`. Deployment then failed with `XA0010: No available device`, even though `dotnet run` listed the available emulators and `dotnet test -f net11.0-android` correctly entered device selection. The issue also affects the common single-entry form: ```xml <TargetFrameworks>net11.0-android</TargetFrameworks> ``` Although it contains only one framework, this is still evaluated as an outer cross-targeting project. ## Fix - Enumerate target frameworks from the outer evaluation, then probe each TFM-specific inner evaluation for `ComputeAvailableDevices`. - Run device selection only for TFMs that provide the target, preserving mixed device/non-device projects. - Pass each selected `Device` and `RuntimeIdentifier` through the existing per-TFM build, deployment, and test-launch pipeline. - Reuse the device-selection restore across TFMs while retaining RID-specific restores when required. This matches the established `dotnet run` and `dotnet watch` behavior: workload capabilities are checked only after evaluating the selected inner TFM. ## Tests - Model workload behavior by conditionally importing `ComputeAvailableDevices` only when `TargetFramework` is set. - Cover single-entry `TargetFrameworks` without `-f` and verify multiple devices are discovered. - Verify selected devices reach deployment for every supported TFM. - Cover projects where only some TFMs support devices. - Preserve solution and binary-log coverage for copied device test projects. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The review found a crash-prone solution-path exception and a binlog restore-count assertion that is inconsistent with RID-provided device selection behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Backport to release/11.0.1xx that fixes dotnet test device discovery for multi-targeted Microsoft.Testing.Platform projects by probing inner (TFM-specific) evaluations for ComputeAvailableDevices, aligning behavior with dotnet run/dotnet watch.
Changes:
- Evaluate per-TFM inner builds before device selection and reuse those evaluations during project inspection.
- Update solution/project processing to separate parallel evaluation from sequential device selection/build/deploy.
- Expand regression coverage with new device-selection scenarios and updated test assets (targets imported only in inner builds).
File summaries
| File | Description |
|---|---|
| test/TestAssets/TestProjects/DotnetTestDevices/DotnetTestDevices.Device.targets | Adds a workload-like .targets file that defines ComputeAvailableDevices with configurable behavior for tests. |
| test/TestAssets/TestProjects/DotnetTestDevices/DotnetTestDevices.csproj | Imports the new device targets only in inner builds to model workload behavior. |
| test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.cs | Adds/updates tests for multi-targeted device discovery and solution configuration/platform propagation. |
| test/dotnet.Tests/CommandTests/Test/GivenDotnetTestProducesBinaryLog.cs | Updates solution binlog tests to include the new imported .targets file. |
| src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs | Refactors device selection into an evaluation phase + selection phase using pre-evaluated inner builds. |
| src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs | Updates project/solution execution to use the new evaluation+selection pipeline and optimize evaluation reuse. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
Evangelink
approved these changes
Sep 9, 2026
jonathanpeppers
deleted the
jonathanpeppers-backport-test-discovery-11-0-1xx
branch
September 9, 2026 13:20
jonathanpeppers
had a problem deploying
to
copilot-pat-pool
September 9, 2026 13:20 — with
GitHub Actions
Failure
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backport of #56054 to
release/11.0.1xx.Fixes
dotnet testdevice discovery for multi-targeted Microsoft.Testing.Platform projects when workload-provided device targets are imported only by target-framework-specific inner builds.Backport details
SolutionAndProjectUtility.csagainst the release-specific implementation.release/11.0.1xx.