Skip to content

[release/11.0.1xx] Fix dotnet test device discovery for multi-targeted projects - #56170

Merged
jonathanpeppers merged 1 commit into
release/11.0.1xxfrom
jonathanpeppers-backport-test-discovery-11-0-1xx
Sep 9, 2026
Merged

jonathanpeppers merged 1 commit into
release/11.0.1xxfrom
jonathanpeppers-backport-test-discovery-11-0-1xx

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Summary

Backport of #56054 to release/11.0.1xx.

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.

Backport details

## 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>
Copilot AI lite review requested due to automatic review settings September 8, 2026 20:05
@jonathanpeppers
jonathanpeppers requested review from a team as code owners September 8, 2026 20:05
@jonathanpeppers
jonathanpeppers changed the base branch from main to release/11.0.1xx September 8, 2026 20:05

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.

🟡 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

@jonathanpeppers
jonathanpeppers merged commit 244ec51 into release/11.0.1xx Sep 9, 2026
31 of 34 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-backport-test-discovery-11-0-1xx branch September 9, 2026 13:20
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc2 milestone Sep 9, 2026

This branch had an error being deployed

1 failed deployment
copilot-pat-pool — 5743b180 Deployed Sep 9, 2026 by jonathanpeppers via pre_activation #3675
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.

3 participants