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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
|
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 |
gemini 4 hydrogen says this was fixed recently in dotnet/sdk dotnet/sdk#57142 **Examining Device Availability** I'm now carefully examining the error message. It seems the problem lies in running tests without specifying a device when multiple are present. I'll need to figure out how to specify the target device for `dotnet test`. This looks like a configuration issue related to device selection. **Investigating Device Ambiguity** I'm now diving deeper into why `dotnet test --configuration Release --no-build` is failing with "No devices are available." The error suggests an ambiguity in device selection. I'm focusing on the interaction between `.NET 11`, `Microsoft.Testing.Platform`, and the Android project configuration, particularly the `OutputType=Exe` setting. I'm reviewing the `global.json` and solution structure, noting the Android project's target framework and runtime identifiers. **Discovering a Connection** I've hit paydirt! Result `1.1.1`, related to a `dotnet test` error, is exactly what I was looking for. Now, I'm digging deeper into `dotnet/sdk#57120` and the use of `--test-modules` to see if I can find further clues. **Analyzing .NET Regression** I've identified a significant regression in the .NET 11 SDK concerning `dotnet test` within the `Microsoft.Testing.Platform`. It's a known issue, tracked under `dotnet/sdk#57120`, and thankfully, a fix (`#57142`) was recently merged on November 25th or 26th, 2026. **Expanding Test Coverage** I've been working on supporting mobile device and emulator test projects. It appears `dotnet test` is incorrectly invoking device discovery on Android projects within a solution, even when those projects are not test projects themselves. This leads to the "No devices are available" error, causing the test run to abort prematurely. The specific .NET version (`11.0.100`) and the inclusion of an Android app project in the solution are key factors here. **Investigating Build Configurations** I'm now diving deeper into the available workarounds for the .NET 11 regression. I'm focusing on how `--test-modules` interacts with `--no-build` and `--configuration Release`. I need to determine if they're compatible or mutually exclusive, given that the build step already compiles the test projects. Specifically, the workflow uses `dotnet test --configuration Release --no-build` by default; how to optimally combine it with `--test-modules` is key to enabling test execution. **Analyzing Potential Conflicts** I've been looking closely at the interactions of the command-line flags, and, thankfully, section `5.2.8` helped me catch a significant issue. I've realized `--test-modules` is incompatible with a number of other flags. The fact that it bypasses MSBuild project evaluation is really at the heart of the problem. This has saved us from a subtle mistake. I've also checked out the work, and am ready to review the two clean items. **Considering User Options** I've been examining potential workarounds for the conflict I discovered. Option 1 involves running `--test-modules` on built DLLs, bypassing project evaluation entirely. Option 2 suggests using `dotnet test --project` for each test project to isolate and avoid problematic solutions. I need to document these clearly for the user, as they provide useful strategies for handling the issue. **Clarifying Root Causes** I'm now zeroing in on the underlying reason for the incompatibility. I've broken down the problem: It appears that `global.json`'s use of `"runner": "Microsoft.Testing.Platform"` on `.NET 11.0.100` is the key. Specifically, the introduction of mobile testing support in .NET 11 via `ComputeAvailableDevices` has triggered the incompatibility, as the SDK has an active regression. I'm documenting this, so we can give context to the user. I've also found that a solution filter will neatly solve the issues, as I can now create a desktop `.slnf` file, and running `dotnet test --solution Tests.slnf --configuration Release --no-build` addresses it. **Pinpointing The Root Problem** I've been re-examining the specific project files, and it's looking increasingly like the problem is stemming from how the Android project is being treated. I've now confirmed that the `MyAdventure.Android.csproj` file is being used for device discovery even though it's an app, which seems to confirm the bug as outlined in `dotnet/sdk#57120`. I've double-checked that `IsTestingPlatformApplication` isn't set. I'm noting these specifics for clearer documentation. This is a **`.NET 11.0.100` SDK bug** (`dotnet/sdk#57120`, recently fixed upstream in `dotnet/sdk#57142`) affecting solutions that mix regular test projects with an Android/mobile project under `Microsoft.Testing.Platform`. ### Root Cause * Your `global.json` selects `"runner": "Microsoft.Testing.Platform"` on SDK `11.0.100`. * .NET 11 added mobile device/emulator support to `dotnet test` (calling the Android workload's `ComputeAvailableDevices` target). * When `dotnet test --configuration Release --no-build` runs at the repo root, it evaluates `MyAdventure.slnx` and hits `src/MyAdventure.Android/MyAdventure.Android.csproj` (`net11.0-android`). Due to the SDK `11.0.100` regression, `dotnet test` triggers device selection on the Android project even though it is an app project (`IsTestProject` is not set on it), finds no emulator/device on the GitHub Actions runner, and aborts before running your `net11.0` tests. --- ### Workarounds (until a patched SDK lands on GitHub runners) Pick one of these in `.github/workflows/build-and-release.yml`: #### Option 1 (Simplest for CI after `Build`): Use `--test-modules` Because the `Build` step already compiled the test projects, pass the built test DLLs directly to MTP without evaluating the solution: ```yaml - name: Test run: dotnet test --test-modules "tests/*/bin/Release/net11.0/*.Tests.dll" ``` *(Note: Do **not** pass `--configuration` or `--no-build` with `--test-modules` — `--test-modules` skips MSBuild project evaluation and rejects project/build flags.)* #### Option 2: Target each test project with `--project` Running each test project individually keeps `MyAdventure.Android` out of `dotnet test`'s scope: ```yaml - name: Test run: | dotnet test --project tests/MyAdventure.Core.Tests/MyAdventure.Core.Tests.csproj --configuration Release --no-build dotnet test --project tests/MyAdventure.Integration.Tests/MyAdventure.Integration.Tests.csproj --configuration Release --no-build dotnet test --project tests/MyAdventure.UI.Tests/MyAdventure.UI.Tests.csproj --configuration Release --no-build ``` #### Option 3: Use a Solution Filter (`.slnf`) for tests Create a solution filter containing only the three test projects (and their dependencies) and run `dotnet test --solution Tests.slnf --configuration Release --no-build` (which also works locally if you run `dotnet test` via `desktop.sh`).
gemini 4 hydrogen says this was fixed recently in dotnet/sdk dotnet/sdk#57142 **Examining Device Availability** I'm now carefully examining the error message. It seems the problem lies in running tests without specifying a device when multiple are present. I'll need to figure out how to specify the target device for `dotnet test`. This looks like a configuration issue related to device selection. **Investigating Device Ambiguity** I'm now diving deeper into why `dotnet test --configuration Release --no-build` is failing with "No devices are available." The error suggests an ambiguity in device selection. I'm focusing on the interaction between `.NET 11`, `Microsoft.Testing.Platform`, and the Android project configuration, particularly the `OutputType=Exe` setting. I'm reviewing the `global.json` and solution structure, noting the Android project's target framework and runtime identifiers. **Discovering a Connection** I've hit paydirt! Result `1.1.1`, related to a `dotnet test` error, is exactly what I was looking for. Now, I'm digging deeper into `dotnet/sdk#57120` and the use of `--test-modules` to see if I can find further clues. **Analyzing .NET Regression** I've identified a significant regression in the .NET 11 SDK concerning `dotnet test` within the `Microsoft.Testing.Platform`. It's a known issue, tracked under `dotnet/sdk#57120`, and thankfully, a fix (`#57142`) was recently merged on November 25th or 26th, 2026. **Expanding Test Coverage** I've been working on supporting mobile device and emulator test projects. It appears `dotnet test` is incorrectly invoking device discovery on Android projects within a solution, even when those projects are not test projects themselves. This leads to the "No devices are available" error, causing the test run to abort prematurely. The specific .NET version (`11.0.100`) and the inclusion of an Android app project in the solution are key factors here. **Investigating Build Configurations** I'm now diving deeper into the available workarounds for the .NET 11 regression. I'm focusing on how `--test-modules` interacts with `--no-build` and `--configuration Release`. I need to determine if they're compatible or mutually exclusive, given that the build step already compiles the test projects. Specifically, the workflow uses `dotnet test --configuration Release --no-build` by default; how to optimally combine it with `--test-modules` is key to enabling test execution. **Analyzing Potential Conflicts** I've been looking closely at the interactions of the command-line flags, and, thankfully, section `5.2.8` helped me catch a significant issue. I've realized `--test-modules` is incompatible with a number of other flags. The fact that it bypasses MSBuild project evaluation is really at the heart of the problem. This has saved us from a subtle mistake. I've also checked out the work, and am ready to review the two clean items. **Considering User Options** I've been examining potential workarounds for the conflict I discovered. Option 1 involves running `--test-modules` on built DLLs, bypassing project evaluation entirely. Option 2 suggests using `dotnet test --project` for each test project to isolate and avoid problematic solutions. I need to document these clearly for the user, as they provide useful strategies for handling the issue. **Clarifying Root Causes** I'm now zeroing in on the underlying reason for the incompatibility. I've broken down the problem: It appears that `global.json`'s use of `"runner": "Microsoft.Testing.Platform"` on `.NET 11.0.100` is the key. Specifically, the introduction of mobile testing support in .NET 11 via `ComputeAvailableDevices` has triggered the incompatibility, as the SDK has an active regression. I'm documenting this, so we can give context to the user. I've also found that a solution filter will neatly solve the issues, as I can now create a desktop `.slnf` file, and running `dotnet test --solution Tests.slnf --configuration Release --no-build` addresses it. **Pinpointing The Root Problem** I've been re-examining the specific project files, and it's looking increasingly like the problem is stemming from how the Android project is being treated. I've now confirmed that the `MyAdventure.Android.csproj` file is being used for device discovery even though it's an app, which seems to confirm the bug as outlined in `dotnet/sdk#57120`. I've double-checked that `IsTestingPlatformApplication` isn't set. I'm noting these specifics for clearer documentation. This is a **`.NET 11.0.100` SDK bug** (`dotnet/sdk#57120`, recently fixed upstream in `dotnet/sdk#57142`) affecting solutions that mix regular test projects with an Android/mobile project under `Microsoft.Testing.Platform`. ### Root Cause * Your `global.json` selects `"runner": "Microsoft.Testing.Platform"` on SDK `11.0.100`. * .NET 11 added mobile device/emulator support to `dotnet test` (calling the Android workload's `ComputeAvailableDevices` target). * When `dotnet test --configuration Release --no-build` runs at the repo root, it evaluates `MyAdventure.slnx` and hits `src/MyAdventure.Android/MyAdventure.Android.csproj` (`net11.0-android`). Due to the SDK `11.0.100` regression, `dotnet test` triggers device selection on the Android project even though it is an app project (`IsTestProject` is not set on it), finds no emulator/device on the GitHub Actions runner, and aborts before running your `net11.0` tests. --- ### Workarounds (until a patched SDK lands on GitHub runners) Pick one of these in `.github/workflows/build-and-release.yml`: #### Option 1 (Simplest for CI after `Build`): Use `--test-modules` Because the `Build` step already compiled the test projects, pass the built test DLLs directly to MTP without evaluating the solution: ```yaml - name: Test run: dotnet test --test-modules "tests/*/bin/Release/net11.0/*.Tests.dll" ``` *(Note: Do **not** pass `--configuration` or `--no-build` with `--test-modules` — `--test-modules` skips MSBuild project evaluation and rejects project/build flags.)* #### Option 2: Target each test project with `--project` Running each test project individually keeps `MyAdventure.Android` out of `dotnet test`'s scope: ```yaml - name: Test run: | dotnet test --project tests/MyAdventure.Core.Tests/MyAdventure.Core.Tests.csproj --configuration Release --no-build dotnet test --project tests/MyAdventure.Integration.Tests/MyAdventure.Integration.Tests.csproj --configuration Release --no-build dotnet test --project tests/MyAdventure.UI.Tests/MyAdventure.UI.Tests.csproj --configuration Release --no-build ``` #### Option 3: Use a Solution Filter (`.slnf`) for tests Create a solution filter containing only the three test projects (and their dependencies) and run `dotnet test --solution Tests.slnf --configuration Release --no-build` (which also works locally if you run `dotnet test` via `desktop.sh`).
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).