Repository navigation
Only select devices for test projects in dotnet test --solution - #57142
Conversation
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]>
|
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. |
There was a problem hiding this comment.
🟢 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
left a comment
There was a problem hiding this comment.
Just the minor nit, on AGENTS.md
| 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. | ||
|
|
There was a problem hiding this comment.
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.
|
/backport to release/11.0.1xx |
|
Started backporting to |
|
@Evangelink backporting to 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 |
Fixes #57120
Why
On 11.0,
dotnet test --solutionfails withNo devices are available for this projectfor 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 theComputeAvailableDevicestarget, 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
EvaluateProjectForDeviceSelectiongets arequireTestProjectoption. When set, a target framework participates in device selection only if it importsComputeAvailableDevicesand is a test project (IsTestProjectorIsTestingPlatformApplicationistrue).--solutionpath inMSBuildUtilitypassesrequireTestProject: true. That evaluation runs after the solution is restored and built, so the NuGet-imported test-project properties are reliable.IsTestProject/IsTestingPlatformApplicationmay not be set yet, so applying the gate there would wrongly skip real device test projects.src/Cli/AGENTS.mddocuments the invariant.Validation
ItDoesNotSelectDevicesForNonTestProjectsInSolutioninGivenDotnetTestSelectsDevice: a solution with a device test project plus a non-test project that importsComputeAvailableDevicesonly in its inner build and reports zero devices. It fails without the fix (No devices are available) and passes with it.GivenDotnetTestSelectsDevicepass against the locally built redist SDK.Not validated: a full real MAUI solution end to end, and servicing branches (backport need still to be decided).