Add dotnet test --list-devices support for MAUI#54565
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the dotnet test Microsoft Testing Platform (MTP) command to support --list-devices, mirroring the existing dotnet run --list-devices behavior so MAUI/Android/iOS test projects can enumerate device IDs without building or running tests.
Changes:
- Added
dotnet test --list-devicesoption and an early-exit listing flow that callsComputeAvailableDevicesviaRunCommandSelector. - Updated
RunCommandSelector.TrySelectDeviceto accept acommandNameso the printed example uses the invoking command (dotnet runvsdotnet test). - Added integration tests for listing behavior and updated the MTP help snapshot.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet.Tests/CommandTests/Test/snapshots/MTPHelpSnapshotTests.VerifyMTPHelpOutput.verified.txt | Updates dotnet test MTP help snapshot to include --list-devices. |
| test/dotnet.Tests/CommandTests/Test/GivenDotnetTestSelectsDevice.cs | Adds integration tests covering --list-devices scenarios (multi-TFM, single device, missing target, solution error). |
| src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Test/TestCommandDefinition.MicrosoftTestingPlatform.cs | Adds the --list-devices option to the MTP dotnet test command definition. |
| src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs | Passes commandName: "dotnet test" into device selection to render correct examples. |
| src/Cli/dotnet/Commands/Test/MTP/Options.cs | Extends BuildOptions to carry the ListDevices flag. |
| src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs | Wires --list-devices parse result into BuildOptions. |
| src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs | Implements the --list-devices early-exit flow and improves solution handling for --device. |
| src/Cli/dotnet/Commands/Run/RunCommandSelector.cs | Adds commandName parameter to TrySelectDevice and uses it in example output. |
| src/Cli/dotnet/Commands/Run/RunCommand.cs | Updates dotnet run to pass commandName: "dotnet run" into TrySelectDevice. |
42c6c89 to
838816d
Compare
838816d to
ea200a3
Compare
Reviewed the diff against 🐛 Bugs / Correctness1.
|
ea200a3 to
baf0f8f
Compare
|
Thanks for the thorough review! Pushed a follow-up commit (squashed into the single commit on the branch). Summary of what I addressed: Adopted:
Skipped (with rationale):
|
00e1144 to
21f746b
Compare
Implements the spec from documentation/general/dotnet-run-for-maui.md to add `--list-devices` and `--device` support to `dotnet test` for MTP-enabled projects. Shares the `RunCommandSelector` plumbing with `dotnet run` so target-framework prompting, MSBuild evaluation, and device discovery all behave consistently between the two commands. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
21f746b to
34938ee
Compare
Expands on #54295 (which added
dotnet test --device) to implement the--list-devicesswitch ondotnet test, as described indotnet-run-for-maui.md. This lets users discover the device identifiers they can pass to--devicefor MAUI/Android/iOS test projects without first having to run a build.Behavior
dotnet test --list-devicesmirrorsdotnet run --list-devices:$(TargetFramework)for multi-targeted projects in interactive mode; errors with a--frameworksuggestion in non-interactive mode.ComputeAvailableDevicesMSBuild target viaRunCommandSelectorand prints the available devices with a friendlydotnet test --device <id>example.ComputeAvailableDevicestarget, exits silently with success (matchesdotnet run --list-devices).Implementation notes
To keep the listing flow structurally identical to
dotnet run --list-devices,HandleListDevicesreuses a singleRunCommandSelectorinstance forTrySelectTargetFramework->InvalidateGlobalProperties->TrySelectDevice(listDevices: true), the same sequence asRunCommand.TrySelectTargetFrameworkAndDeviceIfNeeded.RunCommandSelector.TrySelectDevicegained a requiredcommandNameparameter so the listed/error example rendersdotnet test --device <id>instead of the previously hard-codeddotnet run --device <id>. The two existing call sites (dotnet run, per-TFM device selection in tests) pass"dotnet run"and"dotnet test"respectively.Code review surfaced a separate latent bug from #54295: when
--devicewas used against a solution, the error told users to specify--frameworkeven though that wouldn't fix the failure. Both--deviceand--list-devicesnow throwTestCommandUseProject(Specifying a project for 'dotnet test' should be via '--project'.).Tests
Five new integration tests in
GivenDotnetTestSelectsDevice:-f-fComputeAvailableDevices--projecthint when run against a solutionThe MTP help snapshot is also updated for the new
--list-devicesline.Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>