Skip to content

Commit e798a87

Browse files
authored
Include all platforms in multi project template (dotnet#28766)
* Include all platforms in multi project template * Fix invalid Info.plist value * Update MultiProjectTemplateTest.cs * Update MultiProjectTemplateTest.cs * Update MultiProjectTemplateTest.cs
1 parent 64e88fc commit e798a87

File tree

5 files changed

+81
-14
lines changed

5 files changed

+81
-14
lines changed

src/Templates/src/templates/maui-multiproject/.template.config/template.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@
199199
]
200200
}
201201
},
202-
"XmlEncodedAppNameParam": {
202+
"XmlEncodedAppNameParam": {
203203
"type": "derived",
204204
"valueSource": "name",
205205
"valueTransform": "encode",
206206
"replaces": "XmlEncodedAppName"
207207
},
208-
"defaultAppId":{
208+
"defaultAppId":{
209209
"type": "generated",
210210
"generator": "join",
211211
"parameters": {

src/Templates/src/templates/maui-multiproject/MauiApp.1.Mac/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleDisplayName</key>
6-
<string>MauiApp.1</string>
6+
<string>XmlEncodedAppName</string>
77
<key>CFBundleIdentifier</key>
88
<string>com.companyname.mauiapp</string>
99
<key>CFBundleShortVersionString</key>

src/Templates/src/templates/maui-multiproject/MauiApp.1.iOS/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleDisplayName</key>
6-
<string>MauiApp.1</string>
6+
<string>XmlEncodedAppName</string>
77
<key>CFBundleIdentifier</key>
88
<string>com.companyname.mauiapp</string>
99
<key>CFBundleShortVersionString</key>

src/Templates/src/templates/maui-multiproject/MauiApp.1.sln

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.5.002.0
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
#if (winui)
6+
#if (AllPlatforms || winui)
77
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiApp.1.WinUI", "MauiApp.1.WinUI\MauiApp.1.WinUI.csproj", "{1AA5F22B-62F8-414F-AE50-635E99EB3F76}"
88
EndProject
99
#endif
10-
#if (maccatalyst)
10+
#if (AllPlatforms || maccatalyst)
1111
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiApp.1.Mac", "MauiApp.1.Mac\MauiApp.1.Mac.csproj", "{C2800ABA-8C19-4553-A552-BFF679BEB039}"
1212
EndProject
1313
#endif
14-
#if (ios)
14+
#if (AllPlatforms || ios)
1515
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiApp.1.iOS", "MauiApp.1.iOS\MauiApp.1.iOS.csproj", "{7C064C71-30BE-4D8D-9B68-E7249ED18FA1}"
1616
EndProject
1717
#endif
18-
#if (android)
18+
#if (AllPlatforms || android)
1919
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiApp.1.Droid", "MauiApp.1.Droid\MauiApp.1.Droid.csproj", "{9E30318E-74DD-491B-9BAF-814DC9E892B8}"
2020
EndProject
2121
#endif
@@ -33,7 +33,7 @@ Global
3333
Release|x86 = Release|x86
3434
EndGlobalSection
3535
GlobalSection(ProjectConfigurationPlatforms) = postSolution
36-
#if (winui)
36+
#if (AllPlatforms || winui)
3737
{1AA5F22B-62F8-414F-AE50-635E99EB3F76}.Debug|Any CPU.ActiveCfg = Debug|x64
3838
{1AA5F22B-62F8-414F-AE50-635E99EB3F76}.Debug|Any CPU.Build.0 = Debug|x64
3939
{1AA5F22B-62F8-414F-AE50-635E99EB3F76}.Debug|Any CPU.Deploy.0 = Debug|x64
@@ -59,7 +59,7 @@ Global
5959
{1AA5F22B-62F8-414F-AE50-635E99EB3F76}.Release|x86.Build.0 = Release|x86
6060
{1AA5F22B-62F8-414F-AE50-635E99EB3F76}.Release|x86.Deploy.0 = Release|x86
6161
#endif
62-
#if (maccatalyst)
62+
#if (AllPlatforms || maccatalyst)
6363
{C2800ABA-8C19-4553-A552-BFF679BEB039}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6464
{C2800ABA-8C19-4553-A552-BFF679BEB039}.Debug|Any CPU.Build.0 = Debug|Any CPU
6565
{C2800ABA-8C19-4553-A552-BFF679BEB039}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
@@ -85,7 +85,7 @@ Global
8585
{C2800ABA-8C19-4553-A552-BFF679BEB039}.Release|x86.Build.0 = Release|Any CPU
8686
{C2800ABA-8C19-4553-A552-BFF679BEB039}.Release|x86.Deploy.0 = Release|Any CPU
8787
#endif
88-
#if (ios)
88+
#if (AllPlatforms || ios)
8989
{7C064C71-30BE-4D8D-9B68-E7249ED18FA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
9090
{7C064C71-30BE-4D8D-9B68-E7249ED18FA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
9191
{7C064C71-30BE-4D8D-9B68-E7249ED18FA1}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
@@ -111,7 +111,7 @@ Global
111111
{7C064C71-30BE-4D8D-9B68-E7249ED18FA1}.Release|x86.Build.0 = Release|Any CPU
112112
{7C064C71-30BE-4D8D-9B68-E7249ED18FA1}.Release|x86.Deploy.0 = Release|Any CPU
113113
#endif
114-
#if (android)
114+
#if (AllPlatforms || android)
115115
{9E30318E-74DD-491B-9BAF-814DC9E892B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
116116
{9E30318E-74DD-491B-9BAF-814DC9E892B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
117117
{9E30318E-74DD-491B-9BAF-814DC9E892B8}.Debug|Any CPU.Deploy.0 = Debug|Any CPU

src/TestUtils/src/Microsoft.Maui.IntegrationTests/MultiProjectTemplateTest.cs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@ public void BuildMultiProject(string config, string projectName)
1717
Assert.IsTrue(DotnetInternal.New("maui-multiproject", projectDir, DotNetCurrent),
1818
$"Unable to create template maui-multiproject. Check test output for errors.");
1919

20-
if (!TestEnvironment.IsWindows)
20+
// Always remove WinUI project if the project name contains special characters that cause WinRT source generator issues
21+
// See: https://github.com/microsoft/CsWinRT/issues/1809 (under "Special characters in assembly name" section)
22+
bool containsSpecialChars = projectName.IndexOfAny(new[] { '@', '&', '+', '%', '!', '#', '$', '^', '*', ' ', '-' }) >= 0;
23+
24+
if (!TestEnvironment.IsWindows || containsSpecialChars)
2125
{
2226
Assert.IsTrue(DotnetInternal.Run("sln", $"\"{solutionFile}\" remove \"{projectDir}/{name}.WinUI/{name}.WinUI.csproj\""),
2327
$"Unable to remove WinUI project from solution. Check test output for errors.");
2428
}
2529

26-
Assert.IsTrue(DotnetInternal.Build(solutionFile, config, properties: BuildProps, msbuildWarningsAsErrors: true),
30+
// TODO, we should not need this but hitting: https://github.com/dotnet/maui/issues/19840
31+
var buildProps = BuildProps;
32+
buildProps.Add("ResizetizerErrorOnDuplicateOutputFilename=false");
33+
34+
Assert.IsTrue(DotnetInternal.Build(solutionFile, config, properties: buildProps, msbuildWarningsAsErrors: true),
2735
$"Solution {name} failed to build. Check test output/attachments for errors.");
2836
}
2937

@@ -50,4 +58,63 @@ public void BuildMultiProjectSinglePlatform(string config, string platformArg)
5058
Assert.IsTrue(DotnetInternal.Build(solutionFile, config, properties: BuildProps, msbuildWarningsAsErrors: true),
5159
$"Solution {name} failed to build. Check test output/attachments for errors.");
5260
}
61+
62+
[Test]
63+
[TestCase("--android")]
64+
[TestCase("--ios")]
65+
[TestCase("--windows")]
66+
[TestCase("--macos")]
67+
[TestCase("")] // no platform arg means all platforms
68+
// https://github.com/dotnet/maui/issues/28695
69+
public void VerifyIncludedPlatformsInSln(string platformArg)
70+
{
71+
var projectDir = TestDirectory;
72+
var name = Path.GetFileName(projectDir);
73+
var solutionFile = Path.Combine(projectDir, $"{name}.sln");
74+
75+
Assert.IsTrue(DotnetInternal.New($"maui-multiproject {platformArg}", projectDir, DotNetCurrent),
76+
$"Unable to create template maui-multiproject. Check test output for errors.");
77+
78+
var slnListOutput = DotnetInternal.RunForOutput("sln", $"{solutionFile} list", out int exitCode);
79+
80+
// Asserts the process completed successfully
81+
Assert.AreEqual(0, exitCode, $"Unable to list projects in solution. Check test output for errors.");
82+
83+
// Asserts if the shared project is included in the solution, this should always be the case
84+
Assert.IsTrue(slnListOutput.Contains($"{name}.csproj", StringComparison.OrdinalIgnoreCase),
85+
$"Expected shared project (with name {name}.csproj) to be included in the solution.");
86+
87+
var expectedCsprojFiles = new List<string> { "Droid.csproj", "iOS.csproj", "Mac.csproj", "WinUI.csproj" };
88+
89+
switch (platformArg)
90+
{
91+
case "--android":
92+
expectedCsprojFiles.Remove("iOS.csproj");
93+
expectedCsprojFiles.Remove("WinUI.csproj");
94+
expectedCsprojFiles.Remove("Mac.csproj");
95+
break;
96+
case "--ios":
97+
expectedCsprojFiles.Remove("Droid.csproj");
98+
expectedCsprojFiles.Remove("WinUI.csproj");
99+
expectedCsprojFiles.Remove("Mac.csproj");
100+
break;
101+
case "--windows":
102+
expectedCsprojFiles.Remove("Droid.csproj");
103+
expectedCsprojFiles.Remove("iOS.csproj");
104+
expectedCsprojFiles.Remove("Mac.csproj");
105+
break;
106+
case "--macos":
107+
expectedCsprojFiles.Remove("Droid.csproj");
108+
expectedCsprojFiles.Remove("iOS.csproj");
109+
expectedCsprojFiles.Remove("WinUI.csproj");
110+
break;
111+
}
112+
113+
// Depending on the platform argument, we assert if the expected projects are included in the solution
114+
foreach (var platformCsproj in expectedCsprojFiles)
115+
{
116+
Assert.IsTrue(slnListOutput.Contains(platformCsproj, StringComparison.Ordinal),
117+
$"Expected {platformCsproj} to be included in the solution.");
118+
}
119+
}
53120
}

0 commit comments

Comments
 (0)