Skip to content

Fix dotnet test device discovery for multi-targeted projects - #56054

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-android-test-emulator
Sep 8, 2026
Merged

jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-android-test-emulator

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

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. Its MauiTest1.csproj uses TargetFrameworks for Android, iOS, and Mac Catalyst.

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:

<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.

Copilot AI lite review requested due to automatic review settings August 31, 2026 20:57
@jonathanpeppers
jonathanpeppers requested a review from a team as a code owner August 31, 2026 20:57
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🔵 Needs a closer look

Pull request overview

This PR updates the dotnet test device-selection pipeline for Microsoft.Testing.Platform projects so that device discovery works for multi-targeted (TargetFrameworks) projects where workload/device targets are only imported in TFM-specific inner builds (i.e., after TargetFramework is set). It also extends the existing DotnetTestDevices test asset and adds new integration coverage to prevent regressions.

Changes:

  • Update device discovery to enumerate TFMs from the outer evaluation, then probe each TFM-specific inner evaluation for ComputeAvailableDevices before running device selection.
  • Track whether device-selection restore was performed and use it to suppress redundant restore in subsequent per-TFM builds when applicable.
  • Refactor the DotnetTestDevices test asset to conditionally import ComputeAvailableDevices only in inner builds, and add new dotnet.Tests coverage for the multi-targeting scenarios.
File summaries
File Description
test/TestAssets/TestProjects/DotnetTestDevices/DotnetTestDevices.Device.targets New targets file providing ComputeAvailableDevices for the test asset.
test/TestAssets/TestProjects/DotnetTestDevices/DotnetTestDevices.csproj Import device targets only when TargetFramework is set (inner-build behavior).
test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.cs Add integration tests validating device discovery in cross-targeting outer evaluations and mixed-TFM support.
test/dotnet.Tests/CommandTests/Test/GivenDotnetTestProducesBinaryLog.cs Ensure solution/binlog scenarios copy the extracted device targets file as part of test setup.
src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs Probe per-TFM evaluations for ComputeAvailableDevices; track restore-performed status through device selection result.
src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs Use the new restore-performed signal to avoid redundant restore in per-TFM builds when no RID-specific restore is needed.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0
  • Review effort level: Lite

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found two issues: one correctness gap in solution-specific project property handling and one large-solution performance regression.

Note

This review was generated with AI assistance.

@jonathanpeppers
jonathanpeppers force-pushed the jonathanpeppers-android-test-emulator branch from 743b38b to 51c7a62 Compare September 1, 2026 14:39

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two issues remain: a cross-platform regression test failure and an unresolved large-solution evaluation performance regression.

Probe ComputeAvailableDevices per target framework so workload targets imported only by inner builds participate in device selection. Reuse the device-selection restore across target frameworks and cover mixed device projects.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 044214d8-b337-4b2c-b368-975cf2ea166d
@jonathanpeppers
jonathanpeppers force-pushed the jonathanpeppers-android-test-emulator branch from 51c7a62 to 3c8cdb3 Compare September 8, 2026 16:44

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the updated head. The cross-platform solution-mapping test failure is addressed, but the large-solution performance concern remains: inner-TFM evaluation for every project is still performed in the sequential device-discovery phase. I am not approving yet.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 044214d8-b337-4b2c-b368-975cf2ea166d
@jonathanpeppers
jonathanpeppers force-pushed the jonathanpeppers-android-test-emulator branch from 3c8cdb3 to f87554f Compare September 8, 2026 16:58

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the updated implementation. The solution project and inner-TFM probes now run in parallel, while device selection and per-TFM device builds remain serialized in solution order. The previous cross-platform test issue and large-solution performance concern are addressed.

@jonathanpeppers
jonathanpeppers merged commit bb31fca into main Sep 8, 2026
27 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-android-test-emulator branch September 8, 2026 19:48
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/backport to release/11.0.1xx

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0.1xx (link to workflow run)

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

@jonathanpeppers backporting to release/11.0.1xx failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick bb31fcacf528763377dce5113d04dcbec40eec7a

Auto-merging src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
Auto-merging src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs
CONFLICT (content): Merge conflict in src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs
error: could not apply bb31fcacf5... [dotnet test] Fix device discovery for multi-targeted projects (#56054)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix dotnet test device discovery for inner builds
Using index info to reconstruct a base tree...
M	src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
M	src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
Auto-merging src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs
CONFLICT (content): Merge conflict in src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix dotnet test device discovery for inner builds
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 9, 2026
jonathanpeppers added a commit that referenced this pull request Sep 9, 2026
…d projects (#56170)

## 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

- Manually resolved the conflict in `SolutionAndProjectUtility.cs` against the release-specific implementation.
- Preserves the original product and test coverage from #56054.
- Contains a single commit on top of `release/11.0.1xx`.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch had an error being deployed

1 failed deployment
copilot-pat-pool — f87554f8 Deployed Sep 8, 2026 by jonathanpeppers via pre_activation #3335
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