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 4 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
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
65 changes: 52 additions & 13 deletions src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void BuildWithMauiVersion(string id, string framework, string config, boo
//[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 @@ -274,18 +274,23 @@ public void BuildUnpackaged(string id, string framework, string config)

EnableTizen(projectFile);
FileUtilities.ReplaceInFile(projectFile,
"<UseMaui>true</UseMaui>",
"<UseMaui>true</UseMaui><WindowsPackageType>None</WindowsPackageType>");
"<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.");
}

[Test]
[TestCase("maui", true, true)]
[TestCase("maui", true, false)]
[TestCase("maui", false, true)]
public void BuildWindowsAppSDKSelfContained(string id, bool wasdkself, bool netself)
[TestCase("maui", true, true, "None")]
[TestCase("maui", true, true, "MSIX")]
[TestCase("maui", true, false, "None")]
[TestCase("maui", true, false, "MSIX")]
[TestCase("maui", false, true, "None")]
[TestCase("maui", false, true, "MSIX")]
[TestCase("maui", false, false, "None")]
[TestCase("maui", false, false, "MSIX")]
public void BuildWindowsAppSDKSelfContained(string id, bool wasdkself, bool netself, string packageType)
{
if (TestEnvironment.IsMacOS)
Assert.Ignore("This test is designed for testing a windows build.");
Expand All @@ -297,17 +302,17 @@ 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>
""");

var extendedBuildProps = BuildProps;
extendedBuildProps.Add($"TargetFramework={DotNetCurrent}-windows10.0.19041.0");

Assert.IsTrue(DotnetInternal.Build(projectFile, "Release", properties: extendedBuildProps, msbuildWarningsAsErrors: true),
Assert.IsTrue(DotnetInternal.Build(projectFile, "Debug", properties: extendedBuildProps, msbuildWarningsAsErrors: true),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

Expand All @@ -328,17 +333,16 @@ 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>
""");

var extendedBuildProps = BuildProps;
extendedBuildProps.Add($"TargetFramework={DotNetCurrent}-windows10.0.19041.0");

Assert.IsTrue(DotnetInternal.Build(projectFile, "Release", properties: extendedBuildProps, msbuildWarningsAsErrors: true),
Assert.IsTrue(DotnetInternal.Build(projectFile, "Debug", properties: extendedBuildProps, msbuildWarningsAsErrors: true),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

Expand Down Expand Up @@ -462,6 +466,7 @@ private List<string> PrepareNativeAotBuildProps()

[Test]
[TestCase("maui", DotNetCurrent, "Release")]
[TestCase("maui-blazor", DotNetCurrent, "Release")]
public void PublishUnpackaged(string id, string framework, string config)
{
if (!TestEnvironment.IsWindows)
Expand Down Expand Up @@ -494,6 +499,40 @@ void AssetExists(string filename)
}
}

[Test]
[TestCase("maui", DotNetCurrent, "Release")]
[TestCase("maui-blazor", DotNetCurrent, "Release")]
public void PublishPackaged(string id, string framework, string config)
{
if (!TestEnvironment.IsWindows)
Assert.Ignore("Running Windows templates is only supported on Windows.");

var projectDir = TestDirectory;
var name = Path.GetFileName(projectDir);
var projectFile = Path.Combine(projectDir, $"{name}.csproj");

Assert.IsTrue(DotnetInternal.New(id, projectDir, framework),
$"Unable to create template {id}. Check test output for errors.");

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.");

var assetsRoot = Path.Combine(projectDir, $"bin/{config}/{framework}-windows10.0.19041.0/win10-x64/AppPackages/{name}_1.0.0.1_Test");

AssetExists($"{name}_1.0.0.1_x64.msi");

void AssetExists(string filename)
{
var fullpath = Path.Combine(assetsRoot!, filename);
Assert.IsTrue(File.Exists(fullpath),
$"Unable to find expected asset: {fullpath}");
}
}

/// <summary>
/// Tests the scenario where a .NET MAUI Library specifically uses UseMauiCore instead of UseMaui.
/// </summary>
Expand Down