Skip to content

Only select devices for test projects in dotnet test --solution - #57142

Merged
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/investigate-test-no-devices
Nov 16, 2026
Merged

Evangelink merged 2 commits into
mainfrom
dev/amauryleve/investigate-test-no-devices

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Fixes #57120

Why

On 11.0, dotnet test --solution fails with No devices are available for this project for solutions that contain a MAUI app (or other workload project) alongside the test project. 10.0.404 works. The solution path probes every project's inner build for the ComputeAvailableDevices target, and MAUI app/library heads import that target through their workload. When such a non-test project has no devices available, device selection fails the whole run even though that project is never executed as a test module. The regression came with the device-selection-in-solutions work (#56054 / #56170).

Change

  • EvaluateProjectForDeviceSelection gets a requireTestProject option. When set, a target framework participates in device selection only if it imports ComputeAvailableDevices and is a test project (IsTestProject or IsTestingPlatformApplication is true).
  • The --solution path in MSBuildUtility passes requireTestProject: true. That evaluation runs after the solution is restored and built, so the NuGet-imported test-project properties are reliable.
  • The single-project path keeps its existing behavior. It evaluates before restore, when IsTestProject / IsTestingPlatformApplication may not be set yet, so applying the gate there would wrongly skip real device test projects.
  • src/Cli/AGENTS.md documents the invariant.

Validation

  • New test ItDoesNotSelectDevicesForNonTestProjectsInSolution in GivenDotnetTestSelectsDevice: a solution with a device test project plus a non-test project that imports ComputeAvailableDevices only in its inner build and reports zero devices. It fails without the fix (No devices are available) and passes with it.
  • All 46 tests in GivenDotnetTestSelectsDevice pass against the locally built redist SDK.
  • Manually reproduced the issue on 11.0.100 and confirmed 10.0.404 succeeds.

Not validated: a full real MAUI solution end to end, and servicing branches (backport need still to be decided).

Evangelink and others added 2 commits November 16, 2026 10:58
Since #56054 device probing evaluates per-TFM inner builds, so MAUI app and
library projects in a solution (which import ComputeAvailableDevices in their
-android inner builds) were routed into device selection and failed with
'No devices are available for this project'. Restrict solution-mode device
selection to test projects.

Fixes #57120

Co-authored-by: Copilot App <[email protected]>
Reproduce the reported no-device failure instead of only a multiple-device failure, and assert that device discovery runs only for test frameworks. Link contributor guidance to the implementation.

Co-authored-by: Copilot App <[email protected]>
@Evangelink
Evangelink requested review from a team, lbussell and mthalman as code owners November 16, 2026 10:21
Copilot AI balanced review requested due to automatic review settings November 16, 2026 10:21
@azure-pipelines

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

@Evangelink
Evangelink enabled auto-merge (squash) November 16, 2026 10:26
@Evangelink
Evangelink requested review from jonathanpeppers and removed request for lbussell and mthalman November 16, 2026 10:27

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.

🟢 Approval recommended

There are no active review issues for the change limiting solution device selection to test projects.

No open issues 🎉

What changed in this PR

Fixes the dotnet test --solution regression where non-test workload projects, such as MAUI apps, trigger device selection and prevent tests from running.

Changes:

  • Limits solution device selection to frameworks marked as test projects, while preserving single-project behavior before restore.
  • Adds regression coverage for a solution containing a device test project and a non-test project with no available devices.
  • Documents the solution-only filtering requirement.
File Description
test/​dotnet.Tests/​CommandTests/​Test/​GivenDotnetTestSelectsDevice.cs Adds regression coverage verifying only test projects discover and deploy to devices.
src/​Cli/​dotnet/​Commands/​Test/​MTP/​SolutionAndProjectUtility.cs Adds optional test-project filtering to device-selection eligibility.
src/​Cli/​dotnet/​Commands/​Test/​MTP/​MSBuildUtility.cs Enables filtering for solution runs after restore and build.
src/​Cli/​AGENTS.md Documents why solution and single-project device selection use different eligibility checks.

Review effort: Balanced

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

Just the minor nit, on AGENTS.md

Comment thread src/Cli/AGENTS.md
Comment on lines +127 to +132
In `--solution` runs,
[`device selection`](dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs) applies only to
test projects (`IsTestProject` or `IsTestingPlatformApplication`). App and library projects, such as
MAUI heads, can import `ComputeAvailableDevices` in their inner builds and must not prompt for a device. The single-project
path evaluates before restore, so it must not apply this NuGet-dependent gate.

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.

I would think you could discard the changes to this file. I don't think this paragraph is needed for agents working on this repo.

@Evangelink
Evangelink merged commit 75c968b into main Nov 16, 2026
31 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/investigate-test-no-devices branch November 16, 2026 14:21
@Evangelink

Copy link
Copy Markdown
Member Author

/backport to release/11.0.1xx

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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

git am output
$ git cherry-pick 75c968b7402f7c39fe695968769026688ae26663

Auto-merging src/Cli/AGENTS.md
CONFLICT (content): Merge conflict in src/Cli/AGENTS.md
Auto-merging src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
Auto-merging src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs
Auto-merging test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.cs
error: could not apply 75c968b740... Only select devices for test projects in dotnet test --solution (#57142)
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: Only select devices for test projects in dotnet test --solution
Using index info to reconstruct a base tree...
M	src/Cli/AGENTS.md
M	src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
M	src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs
M	test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Cli/AGENTS.md
CONFLICT (content): Merge conflict in src/Cli/AGENTS.md
Auto-merging src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
Auto-merging src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs
Auto-merging test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.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 Only select devices for test projects in dotnet test --solution
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

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.

[11.0 regression] dotnet test error: No devices are available for this project

3 participants