Skip to content

[release/10.0.1xx] [msbuild/dotnet] Add support for listing the devices and simulators available to run on.#24543

Merged
rolfbjarne merged 5 commits intorelease/10.0.1xxfrom
dev/rolf/backport-pr-24542-release/10.0.1xx-2026-01-22
Jan 22, 2026
Merged

[release/10.0.1xx] [msbuild/dotnet] Add support for listing the devices and simulators available to run on.#24543
rolfbjarne merged 5 commits intorelease/10.0.1xxfrom
dev/rolf/backport-pr-24542-release/10.0.1xx-2026-01-22

Conversation

@rolfbjarne
Copy link
Member

@rolfbjarne rolfbjarne commented Jan 22, 2026

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.
  • Don't return an arm64 simulator on an x64 machine.
  • RuntimeIdentifier, if specified on the command-line.

References:

Fixes #23995.

Backport of #24279.

…mulators available 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.
Copy link
Contributor

Copilot AI left a 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 and selecting iOS/tvOS devices and simulators for dotnet run, implementing the .NET SDK device selection specification. It's a backport from #24279 and #24542 to the release/10.0.1xx branch.

Changes:

  • Adds GetAvailableDevices MSBuild task to query devices/simulators from devicectl and simctl
  • Introduces Device property to replace _DeviceName for specifying target devices
  • Splits mobile and desktop-specific MSBuild targets into separate files for better organization

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tools/common/JsonExtensions.cs New utility class providing JSON parsing extension methods
msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs Core MSBuild task that queries and filters available devices/simulators
tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetAvailableDevicesTest.cs Comprehensive test coverage with multiple test scenarios
dotnet/targets/Microsoft.Sdk.Mobile.targets Extracted mobile-specific targets including ComputeAvailableDevices
dotnet/targets/Microsoft.Sdk.Desktop.targets Extracted desktop-specific targets for macOS/Catalyst
dotnet/targets/Xamarin.Shared.Sdk.targets Updated to import new mobile/desktop targets conditionally
docs/building-apps/build-targets.md Documents the new ComputeAvailableDevices target
docs/building-apps/build-properties.md Documents the new Device property
msbuild/Xamarin.MacDev.Tasks/Tasks/GetMlaunchArguments.cs Refactored product family mapping logic
tests/common/shared-dotnet.mk Updated to use Device property instead of _DeviceName
tests/dotnet/MultiFrameworkApp/* New test project for multi-framework scenarios

using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading;
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DllImport attribute requires using System.Runtime.InteropServices, but this using directive is missing from the file.

Suggested change
using System.Threading;
using System.Threading;
using System.Runtime.InteropServices;

Copilot uses AI. Check for mistakes.

System.Threading.Tasks.Task<IEnumerable<DeviceInfo>> RunSimCtlAsync ()
{
var doc = ExecuteCtlToJsonAsync ("simctl", "list", "--json").Result;
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using .Result on an async method (ExecuteCtlToJsonAsync) in a synchronous method (RunSimCtlAsync) can cause deadlocks in certain contexts. Consider making RunSimCtlAsync properly async or using .GetAwaiter().GetResult() if there's a specific reason it can't be async.

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +30
public string AppBundleManifestPath { get; set; } = string.Empty;

[Output]
public ITaskItem [] Devices { get; set; } = Array.Empty<ITaskItem> ();

[Output]
public ITaskItem [] DiscardedDevices { get; set; } = Array.Empty<ITaskItem> ();

public string RuntimeIdentifier { get; set; } = "";

public string SdkDevPath { get; set; } = "";
Copy link

Copilot AI Jan 22, 2026

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, use "" for empty string, not string.Empty. While the guidelines say to use "" for empty strings, this file consistently uses string.Empty for property initializations which is acceptable in this context for MSBuild task properties. However, for consistency within the codebase guidelines, consider using "" where appropriate.

Copilot generated this review using guidance from repository custom instructions.
$ dotnet run --device UDID
```

Added in .NET 11.
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states this was "Added in .NET 11" but this PR is being backported to the "release/10.0.1xx" branch according to the PR title. The version number in the documentation should reflect the actual release version where this feature is available, which appears to be .NET 10 based on the branch name.

Suggested change
Added in .NET 11.
Added in .NET 10.

Copilot uses AI. Check for mistakes.
Comment on lines +131 to +149
class DeviceInfo {
public ITaskItem Item { get; set; }
public IEnumerable<string> RuntimeIdentifiers { get; set; }
public ApplePlatform Platform { get; set; }
public IPhoneDeviceType DeviceType { get; set; }
public Version MinimumOSVersion { get; set; }
public Version MaximumOSVersion { get; set; }
public string DiscardedReason { get; set; }
public bool Discarded { get => !string.IsNullOrEmpty (DiscardedReason); }
public DeviceInfo (ITaskItem item, IEnumerable<string> runtimeIdentifiers, ApplePlatform platform, IPhoneDeviceType deviceType, Version minimumOSVersion, Version maximumOSVersion, string discardedReason)
{
Item = item;
RuntimeIdentifiers = runtimeIdentifiers;
Platform = platform;
DeviceType = deviceType;
MinimumOSVersion = minimumOSVersion;
MaximumOSVersion = maximumOSVersion;
DiscardedReason = discardedReason;
}
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DeviceInfo class has properties without null-forgiving operators or proper nullable initialization. The properties Item, RuntimeIdentifiers, Platform, DeviceType, MinimumOSVersion, MaximumOSVersion, and DiscardedReason are all initialized through the constructor, so they should either be marked as required or have default values to satisfy nullable reference type requirements properly.

Copilot uses AI. Check for mistakes.
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #c65688f] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: c65688f81a95de3faeac437286ea79606290e3b7 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: c65688f81a95de3faeac437286ea79606290e3b7 [PR build]

@rolfbjarne rolfbjarne enabled auto-merge (squash) January 22, 2026 17:29
@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #c65688f] Build passed (Build packages) ✅

Pipeline on Agent
Hash: c65688f81a95de3faeac437286ea79606290e3b7 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #c65688f] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: c65688f81a95de3faeac437286ea79606290e3b7 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #c65688f] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: c65688f81a95de3faeac437286ea79606290e3b7 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #c65688f] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: c65688f81a95de3faeac437286ea79606290e3b7 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #c65688f] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: c65688f81a95de3faeac437286ea79606290e3b7 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #c65688f] Tests on macOS arm64 - Mac Tahoe (26) passed 💻

All tests on macOS arm64 - Mac Tahoe (26) passed.

Pipeline on Agent
Hash: c65688f81a95de3faeac437286ea79606290e3b7 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #c65688f] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: c65688f81a95de3faeac437286ea79606290e3b7 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build #c65688f] 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
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 9 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: c65688f81a95de3faeac437286ea79606290e3b7 [PR build]

@rolfbjarne rolfbjarne merged commit b364fe5 into release/10.0.1xx Jan 22, 2026
50 of 51 checks passed
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.

4 participants