From f52f9627bbd953119feaf134f6e6bebe915f7059 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 7 Sep 2026 19:43:48 +0200 Subject: [PATCH 1/3] [msbuild] Discard any simulators we get from devicectl in the GetAvailableDevices task. In Xcode 27+, `devicectl` returns simulators too. Discard any simulators we get from `devicectl` (the json output from `devicectl` doesn't contain all the information we need) that matches an existing simulator we got from `simctl`. --- .../Tasks/GetAvailableDevices.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs index 2edf22bf8d64..7a2a6db033a6 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs @@ -45,9 +45,12 @@ public override bool Execute () System.Threading.Tasks.Task.WhenAll (new [] { devicectlTask, simctlTask }).Wait (cancellationTokenSource.Token); var devices = new List (); - devices.AddRange (devicectlTask.Result); devices.AddRange (simctlTask.Result); + // devicectl may return simulators as well, so exclude any devices we've already added + var devicectlDevices = devicectlTask.Result; + devices.AddRange (devicectlDevices.Where (dev => !devices.Any (sim => sim.Udid == dev.Udid))); + // filter to the current platform foreach (var d in devices.Where (d => !d.Discarded && d.Platform != Platform)) d.DiscardedReason = $"Device platform '{d.Platform.AsString ()}' does not match the requested platform '{Platform.AsString ()}'"; @@ -133,15 +136,17 @@ public override bool Execute () class DeviceInfo { public ITaskItem Item { get; set; } + public string Udid { get; set; } public IEnumerable RuntimeIdentifiers { get; set; } public ApplePlatform Platform { get; set; } public IPhoneDeviceType DeviceType { get; set; } public Version MinimumOSVersion { get; set; } public string DiscardedReason { get; set; } public bool Discarded { get => !string.IsNullOrEmpty (DiscardedReason); } - public DeviceInfo (ITaskItem item, IEnumerable runtimeIdentifiers, ApplePlatform platform, IPhoneDeviceType deviceType, Version minimumOSVersion, string discardedReason) + public DeviceInfo (ITaskItem item, string udid, IEnumerable runtimeIdentifiers, ApplePlatform platform, IPhoneDeviceType deviceType, Version minimumOSVersion, string discardedReason) { Item = item; + Udid = udid; RuntimeIdentifiers = runtimeIdentifiers; Platform = platform; DeviceType = deviceType; @@ -252,7 +257,7 @@ async System.Threading.Tasks.Task> RunDeviceCtlAsync () Version.TryParse (device.OSVersion, out var minimumOSVersion); - rv.Add (new DeviceInfo (item, [runtimeIdentifier], platform, deviceType, minimumOSVersion ?? new Version (0, 0), discardedReason)); + rv.Add (new DeviceInfo (item, udid, [runtimeIdentifier], platform, deviceType, minimumOSVersion ?? new Version (0, 0), discardedReason)); } return rv; } @@ -390,7 +395,7 @@ async System.Threading.Tasks.Task> RunSimCtlAsync () } } - rv.Add (new DeviceInfo (item, runtimeIdentifiers, platform, deviceType, minimumOSVersion, discardedReason)); + rv.Add (new DeviceInfo (item, device.Udid, runtimeIdentifiers, platform, deviceType, minimumOSVersion, discardedReason)); } return rv; } From f150013f6e655d16d201db32c64d8ce587bcfedc Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 8 Sep 2026 09:17:01 +0200 Subject: [PATCH 2/3] [msbuild] Address GetAvailableDevices review feedback Use a hash set for UDID deduplication and add regression coverage for duplicate devicectl simulators. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../Tasks/GetAvailableDevices.cs | 7 +++++-- .../TaskTests/GetAvailableDevicesTest.cs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs index 7a2a6db033a6..1f3369585072 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs @@ -48,8 +48,11 @@ public override bool Execute () devices.AddRange (simctlTask.Result); // devicectl may return simulators as well, so exclude any devices we've already added - var devicectlDevices = devicectlTask.Result; - devices.AddRange (devicectlDevices.Where (dev => !devices.Any (sim => sim.Udid == dev.Udid))); + var existingUdids = new HashSet (devices.Select (d => d.Udid), StringComparer.OrdinalIgnoreCase); + foreach (var device in devicectlTask.Result) { + if (existingUdids.Add (device.Udid)) + devices.Add (device); + } // filter to the current platform foreach (var d in devices.Where (d => !d.Discarded && d.Platform != Platform)) diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetAvailableDevicesTest.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetAvailableDevicesTest.cs index a163c857666c..1e18de291c77 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetAvailableDevicesTest.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetAvailableDevicesTest.cs @@ -121,6 +121,20 @@ public void DeviceCtlJsonVersion5 () }); } + [Test] + public void DeviceCtlDuplicateSimulator () + { + var platform = ApplePlatform.iOS; + var task = CreateTask (platform, SIMCTL_JSON_1, DEVICECTL_JSON_1.Replace ("00008003-012301230123ABCD", "3F1C114D-FC3D-481A-9CA1-499EE1339390")); + Assert.That (task.Execute (), Is.True, "Task should have succeeded."); + + Assert.Multiple (() => { + Assert.That (task.Devices.Count, Is.EqualTo (4), "Devices count mismatch."); + Assert.That (task.Devices.Count (d => d.ItemSpec == "3F1C114D-FC3D-481A-9CA1-499EE1339390"), Is.EqualTo (1), "Duplicate simulator count mismatch."); + Assert.That (task.Devices.Single (d => d.ItemSpec == "3F1C114D-FC3D-481A-9CA1-499EE1339390").GetMetadata ("Type"), Is.EqualTo ("Simulator"), "Simulator metadata mismatch."); + }); + } + [Test] public void SimCtl1 () { From 865730604237d842ee155ae77bb71ad790a093a7 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 9 Sep 2026 18:23:43 +0200 Subject: [PATCH 3/3] [msbuild] Preserve device ordering when filtering duplicates Filter devicectl results against the simulator UDIDs before appending simctl results. This keeps simctl authoritative for duplicate simulator entries without changing the established physical-device-first ordering used by discarded-device results and tests.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs index 1f3369585072..e9e62df5ae47 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs @@ -45,14 +45,13 @@ public override bool Execute () System.Threading.Tasks.Task.WhenAll (new [] { devicectlTask, simctlTask }).Wait (cancellationTokenSource.Token); var devices = new List (); - devices.AddRange (simctlTask.Result); - - // devicectl may return simulators as well, so exclude any devices we've already added - var existingUdids = new HashSet (devices.Select (d => d.Udid), StringComparer.OrdinalIgnoreCase); + var simulators = simctlTask.Result.ToList (); + var simulatorUdids = new HashSet (simulators.Select (d => d.Udid), StringComparer.OrdinalIgnoreCase); foreach (var device in devicectlTask.Result) { - if (existingUdids.Add (device.Udid)) + if (!simulatorUdids.Contains (device.Udid)) devices.Add (device); } + devices.AddRange (simulators); // filter to the current platform foreach (var d in devices.Where (d => !d.Discarded && d.Platform != Platform))