Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Maui templates to build unpackaged Windows apps by default #23787

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"profiles": {
"Windows Machine": {
"commandName": "MsixPackage",
"commandName": "Project",
"nativeDebugging": false
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Templates/src/templates/maui-blazor/MauiApp.1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>
mattleibow marked this conversation as resolved.
Show resolved Hide resolved

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"profiles": {
"Windows Machine": {
"commandName": "MsixPackage",
"commandName": "Project",
mattleibow marked this conversation as resolved.
Show resolved Hide resolved
"nativeDebugging": false
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Templates/src/templates/maui-mobile/MauiApp.1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"profiles": {
"Windows Machine": {
"commandName": "MsixPackage",
"commandName": "Project",
"nativeDebugging": false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<UseMaui>true</UseMaui>
<!-- We do not want XAML files to be processed as .NET MAUI XAML, but rather WinUI XAML. -->
<EnableDefaultMauiItems>false</EnableDefaultMauiItems>
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"profiles": {
"Windows Machine": {
"commandName": "MsixPackage",
"commandName": "Project",
"nativeDebugging": true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ namespace Microsoft.Maui.IntegrationTests
{
public static class FileUtilities
{
public static void ShouldNotContainInFile(string file, string value)
{
string content = File.ReadAllText(file);

if (content.Contains(value, StringComparison.OrdinalIgnoreCase))
throw new InvalidOperationException($"Found '{value}' in '{file}'.");
}

public static void ShouldContainInFile(string file, string value)
{
string content = File.ReadAllText(file);

if (!content.Contains(value, StringComparison.OrdinalIgnoreCase))
throw new InvalidOperationException($"Unable to find '{value}' in '{file}'.");
}

public static void ReplaceInFile(string file, string oldValue, string newValue)
{
string content = File.ReadAllText(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class WindowsTemplateTest : BaseTemplateTests
[TestCase("maui-blazor", DotNetPrevious, "Release")]
[TestCase("maui-blazor", DotNetCurrent, "Debug")]
[TestCase("maui-blazor", DotNetCurrent, "Release")]
public void BuildUnpackaged(string id, string framework, string config)
public void BuildPackaged(string id, string framework, string config)
{
var projectDir = TestDirectory;
var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj");
Expand All @@ -24,12 +24,19 @@ public void BuildUnpackaged(string id, string framework, string config)
if (framework != DotNetPrevious)
EnableTizen(projectFile);

FileUtilities.ReplaceInFile(projectFile,
"<UseMaui>true</UseMaui>",
"""
<UseMaui>true</UseMaui>
<WindowsPackageType>None</WindowsPackageType>
""");
if (framework == DotNetPrevious)
{
// .NET 8 was Packaged by default, so we don't have to do anything
FileUtilities.ShouldNotContainInFile(projectFile,
"<WindowsPackageType>");
}
else
{
// .NET 9 and later was Unpackaged, so we need to remove the line
FileUtilities.ReplaceInFile(projectFile,
"<WindowsPackageType>None</WindowsPackageType>",
"");
}

Assert.IsTrue(DotnetInternal.Build(projectFile, config, properties: BuildProps, msbuildWarningsAsErrors: true),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
Expand All @@ -56,9 +63,8 @@ public void BuildWindowsAppSDKSelfContained(string id, bool wasdkself, bool nets
$"Unable to create template {id}. Check test output for errors.");

FileUtilities.ReplaceInFile(projectFile,
"<UseMaui>true</UseMaui>",
"<WindowsPackageType>None</WindowsPackageType>",
$"""
<UseMaui>true</UseMaui>
<WindowsAppSDKSelfContained>{wasdkself}</WindowsAppSDKSelfContained>
<SelfContained>{netself}</SelfContained>
<WindowsPackageType>{packageType}</WindowsPackageType>
Expand Down Expand Up @@ -88,9 +94,8 @@ public void BuildWindowsRidGraph(string id, bool useridgraph, string packageType
$"Unable to create template {id}. Check test output for errors.");

FileUtilities.ReplaceInFile(projectFile,
"<UseMaui>true</UseMaui>",
"<WindowsPackageType>None</WindowsPackageType>",
$"""
<UseMaui>true</UseMaui>
<UseRidGraph>{useridgraph}</UseRidGraph>
<WindowsPackageType>{packageType}</WindowsPackageType>
""");
Expand All @@ -104,7 +109,9 @@ public void BuildWindowsRidGraph(string id, bool useridgraph, string packageType

[Test]
[TestCase("maui", DotNetCurrent, "Release")]
[TestCase("maui", DotNetPrevious, "Release")]
[TestCase("maui-blazor", DotNetCurrent, "Release")]
[TestCase("maui-blazor", DotNetPrevious, "Release")]
public void PublishUnpackaged(string id, string framework, string config)
{
if (!TestEnvironment.IsWindows)
Expand All @@ -116,7 +123,19 @@ public void PublishUnpackaged(string id, string framework, string config)
Assert.IsTrue(DotnetInternal.New(id, projectDir, framework),
$"Unable to create template {id}. Check test output for errors.");

BuildProps.Add("WindowsPackageType=None");
if (framework == DotNetPrevious)
{
// .NET 8 was Packaged by default, so we need to say no
FileUtilities.ShouldNotContainInFile(projectFile,
"<WindowsPackageType>");
BuildProps.Add("WindowsPackageType=None");
}
else
{
// .NET 9 is Unpackaged by default, so we don't have to do anything
FileUtilities.ShouldContainInFile(projectFile,
"<WindowsPackageType>None</WindowsPackageType>");
}

Assert.IsTrue(DotnetInternal.Publish(projectFile, config, framework: $"{framework}-windows10.0.19041.0", properties: BuildProps),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
Expand All @@ -139,7 +158,9 @@ void AssetExists(string filename)

[Test]
[TestCase("maui", DotNetCurrent, "Release")]
[TestCase("maui", DotNetPrevious, "Release")]
[TestCase("maui-blazor", DotNetCurrent, "Release")]
[TestCase("maui-blazor", DotNetPrevious, "Release")]
public void PublishPackaged(string id, string framework, string config)
{
if (!TestEnvironment.IsWindows)
Expand All @@ -152,6 +173,20 @@ public void PublishPackaged(string id, string framework, string config)
Assert.IsTrue(DotnetInternal.New(id, projectDir, framework),
$"Unable to create template {id}. Check test output for errors.");

if (framework == DotNetPrevious)
{
// .NET 8 was Packaged by default, so we don't have to do anything
FileUtilities.ShouldNotContainInFile(projectFile,
"<WindowsPackageType>");
}
else
{
// .NET 9 and later was Unpackaged, so we need to remove the line
FileUtilities.ReplaceInFile(projectFile,
"<WindowsPackageType>None</WindowsPackageType>",
"");
}

Assert.IsTrue(DotnetInternal.Publish(projectFile, config, framework: $"{framework}-windows10.0.19041.0", properties: BuildProps),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");

Expand Down