diff --git a/eng/devices/android.cake b/eng/devices/android.cake index f17028459a3f..5712af5843c7 100644 --- a/eng/devices/android.cake +++ b/eng/devices/android.cake @@ -150,8 +150,7 @@ RunTarget(TARGET); void ExecuteBuild(string project, string device, string binDir, string config, string tfm, string toolPath, bool useCoreClr) { var projectName = System.IO.Path.GetFileNameWithoutExtension(project); - bool isUsingCoreClr = useCoreClr.ToString().Equals("true", StringComparison.CurrentCultureIgnoreCase); - var monoRuntime = isUsingCoreClr ? "coreclr" : "mono"; + var monoRuntime = useCoreClr ? "coreclr" : "mono"; var binlog = $"{binDir}/{projectName}-{config}-{monoRuntime}-android.binlog"; DotNetBuild(project, new DotNetBuildSettings @@ -168,7 +167,7 @@ void ExecuteBuild(string project, string device, string binDir, string config, s args.Append("/p:EmbedAssembliesIntoApk=true") .Append("/bl:" + binlog); - if (isUsingCoreClr) + if (useCoreClr) { args.Append("/p:UseMonoRuntime=false"); } diff --git a/eng/devices/catalyst.cake b/eng/devices/catalyst.cake index 4b6ed18054b1..99149b1a50f4 100644 --- a/eng/devices/catalyst.cake +++ b/eng/devices/catalyst.cake @@ -88,7 +88,7 @@ void ExecuteBuild(string project, string binDir, string config, string rid, stri .Append($"/p:RuntimeIdentifier={rid}") .Append($"/bl:{binlog}"); - if (isUsingCoreClr) + if (useCoreClr) { args.Append("/p:UseMonoRuntime=false"); } diff --git a/eng/devices/ios.cake b/eng/devices/ios.cake index 5722f94d49ed..f45716c79530 100644 --- a/eng/devices/ios.cake +++ b/eng/devices/ios.cake @@ -155,7 +155,7 @@ void ExecuteBuild(string project, string device, string binDir, string config, s .Append("/bl:" + binlog) .Append("/tl"); - if (isUsingCoreClr) + if (useCoreClr) { args.Append("/p:UseMonoRuntime=false"); } diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Apple/Simulator.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Apple/Simulator.cs index 64288dd8f7d0..c527285b0e19 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Apple/Simulator.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Apple/Simulator.cs @@ -1,10 +1,14 @@ - +using System.Text.RegularExpressions; + namespace Microsoft.Maui.IntegrationTests.Apple { public class Simulator { readonly string XCRunTool = "xcrun"; + // Regex pattern for valid simulator UDID (UUID format: 8-4-4-4-12 hex characters) + static readonly Regex UdidPattern = new Regex(@"^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$", RegexOptions.Compiled); + public string XHarnessID { get; set; } = System.Environment.GetEnvironmentVariable("IOS_TEST_DEVICE") ?? "ios-simulator-64"; string _udid = ""; @@ -13,7 +17,23 @@ public string GetUDID() if (!string.IsNullOrEmpty(_udid)) return _udid; - return _udid = XHarness.GetSimulatorUDID(XHarnessID).Trim(); + var output = XHarness.GetSimulatorUDID(XHarnessID); + + // The output may contain error messages before the actual UDID. + // Search for a valid UDID pattern in the output. + foreach (var line in output.Split('\n', '\r')) + { + var trimmedLine = line.Trim(); + if (UdidPattern.IsMatch(trimmedLine)) + { + _udid = trimmedLine; + return _udid; + } + } + + // If no valid UDID found, return the trimmed output (will likely cause a meaningful error downstream) + TestContext.WriteLine($"Warning: Could not find valid UDID in xharness output. Full output:\n{output}"); + return _udid = output.Trim(); } public bool Launch() diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AppleTemplateTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AppleTemplateTests.cs index a5b5dd44a3d7..a8be9f402c75 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AppleTemplateTests.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AppleTemplateTests.cs @@ -37,6 +37,10 @@ public void AppleTemplateFxtTearDown() [TestCase("maui-blazor", "Release", DotNetCurrent, "iossimulator-x64", RuntimeVariant.Mono, null)] [TestCase("maui-blazor", "Release", DotNetCurrent, "iossimulator-x64", RuntimeVariant.Mono, "full")] [TestCase("maui", "Release", DotNetCurrent, "iossimulator-x64", RuntimeVariant.NativeAOT, null)] + [TestCase("maui", "Debug", DotNetCurrent, "iossimulator-x64", RuntimeVariant.CoreCLR, null)] + [TestCase("maui", "Release", DotNetCurrent, "iossimulator-x64", RuntimeVariant.CoreCLR, null)] + [TestCase("maui-blazor", "Debug", DotNetCurrent, "iossimulator-x64", RuntimeVariant.CoreCLR, null)] + [TestCase("maui-blazor", "Release", DotNetCurrent, "iossimulator-x64", RuntimeVariant.CoreCLR, null)] public void RunOniOS(string id, string config, string framework, string runtimeIdentifier, RuntimeVariant runtimeVariant, string trimMode) { var projectDir = TestDirectory; @@ -46,14 +50,18 @@ public void RunOniOS(string id, string config, string framework, string runtimeI $"Unable to create template {id}. Check test output for errors."); var buildProps = BuildProps; + buildProps.Add($"RuntimeIdentifier={runtimeIdentifier}"); if (runtimeVariant == RuntimeVariant.NativeAOT) { buildProps.Add("PublishAot=true"); buildProps.Add("PublishAotUsingRuntimePack=true"); // TODO: This parameter will become obsolete https://github.com/dotnet/runtime/issues/87060 buildProps.Add("_IsPublishing=true"); // using dotnet build with -p:_IsPublishing=true enables targeting simulators - buildProps.Add($"RuntimeIdentifier={runtimeIdentifier}"); buildProps.Add("IlcTreatWarningsAsErrors=false"); // TODO: Remove this once all warnings are fixed https://github.com/dotnet/maui/issues/19397 } + else if (runtimeVariant == RuntimeVariant.CoreCLR) + { + buildProps.Add("UseMonoRuntime=false"); + } if (!string.IsNullOrEmpty(trimMode)) { diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseBuildTest.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseBuildTest.cs index 6b3acac4deed..bc17cb8dec39 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseBuildTest.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseBuildTest.cs @@ -5,7 +5,8 @@ namespace Microsoft.Maui.IntegrationTests public enum RuntimeVariant { Mono, - NativeAOT + NativeAOT, + CoreCLR } public abstract class BaseBuildTest