Skip to content

Commit 191be1b

Browse files
authored
[msbuild] Don't execute the ParseDeviceSpecificBuildInformation task on Mac Catalyst. (#22887)
The 'ParseDeviceSpecificBuildInformation' task is only applicable to mobile targets (iOS and tvOS), so skip running it on Mac Catalyst (like we're already doing for macOS). This fixes a build error if happens to run on Mac Catalyst: > The "ParseDeviceSpecificBuildInformation" task failed unexpectedly. System.InvalidOperationException: Invalid platform: MacCatalyst Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2484312.
1 parent 0c8e684 commit 191be1b

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

msbuild/Xamarin.Shared/Xamarin.Shared.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
12321232
will apply to Xamarin.Mac as well.
12331233
-->
12341234
<ParseDeviceSpecificBuildInformation
1235-
Condition="'$(DeviceSpecificBuild)' == 'true' And '$(TargetiOSDevice)' != '' And '$(_CanDeployToDeviceOrSimulator)' == 'true' And '$(_PlatformName)' != 'macOS'"
1235+
Condition="'$(DeviceSpecificBuild)' == 'true' And '$(TargetiOSDevice)' != '' And '$(_CanDeployToDeviceOrSimulator)' == 'true' And '$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'"
12361236
Architectures="$(TargetArchitectures)"
12371237
IntermediateOutputPath="$(IntermediateOutputPath)"
12381238
OutputPath="$(OutputPath)"

tests/common/DotNet.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using System.Text;
8+
using System.Xml;
89

910
using Xamarin.Utils;
1011

@@ -217,15 +218,19 @@ public static ExecutionResult Execute (string verb, string project, Dictionary<s
217218
}
218219
}
219220
if (generatedProps is not null) {
221+
var settings = new XmlWriterSettings ();
220222
var sb = new StringBuilder ();
221-
sb.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
222-
sb.AppendLine ("<Project>");
223-
sb.AppendLine ("\t<PropertyGroup>");
223+
var xml = XmlWriter.Create (sb, settings);
224+
xml.WriteStartElement ("Project");
225+
xml.WriteStartElement ("PropertyGroup");
224226
foreach (var prop in generatedProps) {
225-
sb.AppendLine ($"\t\t<{prop.Key}>{prop.Value}</{prop.Key}>");
227+
xml.WriteStartElement (prop.Key);
228+
xml.WriteString (prop.Value);
229+
xml.WriteEndElement ();
226230
}
227-
sb.AppendLine ("\t</PropertyGroup>");
228-
sb.AppendLine ("</Project>");
231+
xml.WriteEndElement ();
232+
xml.WriteEndElement ();
233+
xml.Flush ();
229234

230235
var generatedProjectFile = Path.Combine (Cache.CreateTemporaryDirectory (), "GeneratedProjectFile.props");
231236
File.WriteAllText (generatedProjectFile, sb.ToString ());

tests/dotnet/UnitTests/MauiTest.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ public class MauiTest : TestBaseClass {
1111
[TestCase (ApplePlatform.iOS, "ios-arm64")]
1212
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64")]
1313
public void BuildMauiApp (ApplePlatform platform, string runtimeIdentifiers)
14+
{
15+
BuildMauiAppImpl (platform, runtimeIdentifiers);
16+
}
17+
18+
void BuildMauiAppImpl (ApplePlatform platform, string runtimeIdentifiers, bool deviceSpecificBuild = false)
1419
{
1520
var project = "MyMauiApp";
1621
Configuration.IgnoreIfIgnoredPlatform (platform);
@@ -21,6 +26,28 @@ public void BuildMauiApp (ApplePlatform platform, string runtimeIdentifiers)
2126
DotNet.InstallWorkload ("maui-tizen");
2227

2328
var properties = GetDefaultProperties (runtimeIdentifiers);
29+
if (deviceSpecificBuild) {
30+
properties ["file:TargetiOSDevice"] =
31+
"""
32+
<?xml version="1.0" encoding="UTF-8"?>
33+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
34+
<plist version="1.0">
35+
<dict>
36+
<key>device</key>
37+
<dict>
38+
<key>architecture</key>
39+
<string>ARM64</string>
40+
<key>os</key>
41+
<string>ios</string>
42+
<key>model</key>
43+
<string>iphone</string>
44+
<key>os-version</key>
45+
<string>18.0</string>
46+
</dict>
47+
</dict>
48+
</plist>
49+
""";
50+
}
2451
var rv = DotNet.AssertBuild (project_path, properties);
2552
AssertThatLinkerExecuted (rv);
2653
var infoPlistPath = GetInfoPListPath (platform, appPath);
@@ -39,5 +66,13 @@ public void BuildMauiApp (ApplePlatform platform, string runtimeIdentifiers)
3966
Assert.AreEqual ("None", linkModeValue, "LinkMode");
4067
Assert.AreEqual ("None", mtouchLinkValue, "MtouchLink");
4168
}
69+
70+
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64")]
71+
// [Category ("RemoteWindows")]
72+
public void BuildMauiAppWithDeviceSpecificBuilds (ApplePlatform platform, string runtimeIdentifiers)
73+
{
74+
// Configuration.IgnoreIfNotOnWindows ();
75+
BuildMauiAppImpl (platform, runtimeIdentifiers, deviceSpecificBuild: true);
76+
}
4277
}
4378
}

0 commit comments

Comments
 (0)