-
Notifications
You must be signed in to change notification settings - Fork 548
[msbuild/dotnet] Add support for listing the devices and simulators available to run on. #24279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: net11.0
Are you sure you want to change the base?
Conversation
…vailable to run on. This consists of two parts: * Add an MSBuild target that lists all the available devices (`ComputeAvailableDevices`), by returning them in a `$(Devices)` item group. * Add support for the `$(Device)` property to specify the device or simulator to use. Regarding the device list, we'll filter the returned list by: * Platform (don't return an Apple TV simulator for an iOS app). * Minimum OS version (not return an iOS 18.0 device when the app's minimum OS version is 26.0). * Only devices that are actually available, as reported by `devicectl` or `simctl`. References: * dotnet/android#10576 * https://github.com/dotnet/sdk/blob/2b9fc02a265c735f2132e4e3626e94962e48bdf5/documentation/specs/dotnet-run-for-maui.md Fixes #23995.
|
@jonathanpeppers I think the spec needs to be updated so that the correct RuntimeIdentifier is set, depending on what the user chose - maybe the returned item group with the devices can have a 'RuntimeIdentifier' metadata that, if specified, is set for the subsequent build/run operation? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for listing available devices and simulators for iOS and tvOS apps, enabling device selection via the dotnet run --device command. The implementation follows the .NET SDK's device selection specification for MAUI-style device management.
Key Changes:
- New
GetAvailableDevicesMSBuild task that queriesdevicectlandsimctlto retrieve available physical devices and simulators - New
ComputeAvailableDevicestarget that can be invoked to list all compatible devices - Property rename from
_DeviceNametoDevicefor specifying target devices
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/common/JsonExtensions.cs | New utility class with JSON parsing extension methods for processing devicectl/simctl output |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetAvailableDevicesTest.cs | Comprehensive test suite covering device filtering scenarios (platform, OS version, device family) |
| msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs | Main task implementation that queries devices, applies filters, and returns available devices |
| msbuild/Xamarin.Shared/Xamarin.Shared.targets | Moved _AppBundleManifestPath property definition to allow access by GetAvailableDevices |
| msbuild/Xamarin.MacDev.Tasks/Xamarin.MacDev.Tasks.csproj | Added JsonExtensions.cs to the project |
| dotnet/targets/Xamarin.Shared.Sdk.targets | Added ComputeAvailableDevices target and Device property with backward compatibility for _DeviceName |
| tests/common/shared-dotnet.mk | Updated to use Device property instead of deprecated _DeviceName |
| docs/building-apps/build-targets.md | Documentation for the new ComputeAvailableDevices target |
| docs/building-apps/build-properties.md | Documentation for the new Device property |
| public ITaskItem [] Devices { get; set; } = Array.Empty<ITaskItem> (); | ||
|
|
||
| [Output] | ||
| public ITaskItem [] DiscardedDevices { get; set; } = Array.Empty<ITaskItem> (); |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the coding guidelines, output properties should be initialized with [] instead of Array.Empty<ITaskItem>(). Change to:
public ITaskItem [] DiscardedDevices { get; set; } = [];| Queries and returns a list of available iOS or tvOS devices and simulators that can be used with `dotnet run`. | ||
|
|
||
| This target is called automatically by the .NET SDK's `dotnet run` command to | ||
| support device selection via the `--device` option. It returns a `@(Devices)`` |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a double backtick after @(Devices). It should be @(Devices) with no trailing backticks.
| support device selection via the `--device` option. It returns a `@(Devices)`` | |
| support device selection via the `--device` option. It returns a `@(Devices)` |
|
|
||
| - **Description**: The name of the device (e.g., "iPhone 16 - iOS 26.0" for simulators, "My iPhone 16" for physical devices) | ||
| - **Type**: Either "Device" or "Simulator" | ||
| - **OSVersion**: The OS version if the device |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar error: should be "The OS version of the device" instead of "The OS version if the device".
| - **OSVersion**: The OS version if the device | |
| - **OSVersion**: The OS version of the device |
| The value can be anything the command-line tools `simctl` or `devicectl` | ||
| accept for the device name; this is typically either the UDID or the name of | ||
| the device. For example, for the device `My iOS Device` with UDID `0000-aaaabbbb`, use | ||
| either `-p:Device="My iOS Device"` or `-p:Device=0000-aaaabbbb`. |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent code formatting: The second command example should use backticks for consistency with the first example. Change -p:Device=0000-aaaabbbb to `-p:Device=0000-aaaabbbb`.
| Target that queries available devices and simulators. | ||
| This target is called by 'dotnet run' to support device selection. | ||
| Returns @(Devices) items with metadata: ??????? |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "Returns @(Devices) items with metadata: ???????" which appears to be a placeholder that was not filled in. The metadata should be documented here (Description, Type, OSVersion, UDID) similar to what's in the build-targets.md documentation.
| Returns @(Devices) items with metadata: ??????? | |
| Returns @(Devices) items with metadata: Description, Type, OSVersion, UDID |
| @@ -0,0 +1,107 @@ | |||
| using System.ComponentModel.DataAnnotations; | |||
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The using System.ComponentModel.DataAnnotations; directive appears to be unused. This namespace is typically used for validation attributes like [Required], but none of the methods in this file use these attributes.
| using System.ComponentModel.DataAnnotations; |
| using System.Net; | ||
|
|
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The using System.Net; directive appears to be unused in this file. Consider removing it to improve code clarity.
| using System.Net; |
| public string AppBundleManifestPath { get; set; } = string.Empty; | ||
|
|
||
| [Output] | ||
| public ITaskItem [] Devices { get; set; } = Array.Empty<ITaskItem> (); |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the coding guidelines, output properties should be initialized with [] instead of Array.Empty<ITaskItem>(). Change to:
public ITaskItem [] Devices { get; set; } = [];
✅ [CI Build #a396aa9] Build passed (Build packages) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #a396aa9] Build passed (Detect API changes) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #a396aa9] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
💻 [CI Build #a396aa9] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #a396aa9] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #a396aa9] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #a396aa9] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💻 [CI Build #a396aa9] Tests on macOS arm64 - Mac Tahoe (26) passed 💻✅ All tests on macOS arm64 - Mac Tahoe (26) passed. Pipeline on Agent |
🚀 [CI Build #a396aa9] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 117 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
| <DeviceName Condition="'$(DeviceName)' == ''">$(_DeviceName)</DeviceName> | ||
| <!-- Try to keep _DeviceName working for a while yet --> | ||
| <Device Condition="'$(Device)' == ''">$(_DeviceName)</Device> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to keep $(DeviceName) around, it's public? Maybe it's not really used/documented.
| Condition="'$(IsMacEnabled)' == 'true'" | ||
| SessionId="$(BuildSessionId)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a question... Will this work on Windows? Ideally, it could, but that could be future PR.
This consists of two parts:
ComputeAvailableDevices), by returning them in a$(Devices)item group.$(Device)property to specify the device or simulator to use.Regarding the device list, we'll filter the returned list by:
devicectlorsimctl.References:
$(Device)andComputeAvailableDevicesMSBuild target android#10576Fixes #23995.