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

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 17, 2026
9034725985 added a commit to kusl/MyAdventure that referenced this pull request Nov 26, 2026
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`).
9034725985 added a commit to kusl/MyAdventure that referenced this pull request Nov 26, 2026
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`).
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