Skip to content

Commit

Permalink
Enable building WASDK Self-Contained packaged apps (#20019)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Jan 24, 2024
1 parent 2c02ada commit ff0aea3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.targets
Expand Up @@ -76,7 +76,7 @@
<!--
Workaround for https://github.com/microsoft/WindowsAppSDK/issues/2684
-->
<Import Project="src\Core\src\nuget\buildTransitive\WinUI.Unpackaged.targets" Condition=" '$(WindowsPackageType)' == 'None' and '$(_MauiTargetPlatformIsWindows)' == 'True' " />
<Import Project="src\Core\src\nuget\buildTransitive\WinUI.targets" Condition=" '$(WindowsPackageType)' == 'None' and '$(_MauiTargetPlatformIsWindows)' == 'True' " />

<!-- NuGet package information -->
<PropertyGroup Condition="'$(IsPackable)' == 'true'">
Expand Down
39 changes: 0 additions & 39 deletions src/Core/src/nuget/buildTransitive/WinUI.Unpackaged.targets

This file was deleted.

32 changes: 31 additions & 1 deletion src/Core/src/nuget/buildTransitive/WinUI.targets
Expand Up @@ -28,7 +28,37 @@

<!--
Workaround for https://github.com/microsoft/WindowsAppSDK/issues/2684
This replaces the error check target entirely as it is not needed.
-->
<Import Project="WinUI.Unpackaged.targets" Condition=" '$(WindowsPackageType)' == 'None' " />
<Target Name="WindowsAppSDKSelfContainedVerifyConfiguration">
</Target>

<!--
Workaround for https://github.com/microsoft/WindowsAppSDK/issues/2684
This adjusts the items if we are still resolving to AnyCPU.
-->
<Target Name="_MAUIAfter_GetExtractMicrosoftWindowsAppSDKMsixFilesInputs"
AfterTargets="GetExtractMicrosoftWindowsAppSDKMsixFilesInputs"
Condition="'$(NativePlatform)' == 'AnyCPU'">
<PropertyGroup>
<NativePlatform>Invalid</NativePlatform>
<NativePlatform Condition="'$(Platform)' == 'x86'">x86</NativePlatform>
<NativePlatform Condition="'$(Platform)' == 'Win32'">x86</NativePlatform>
<NativePlatform Condition="'$(Platform)' == 'x64'">x64</NativePlatform>
<NativePlatform Condition="'$(Platform)' == 'arm'">arm</NativePlatform>
<NativePlatform Condition="'$(Platform)' == 'arm64'">arm64</NativePlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)' == 'AnyCPU'">
<NativePlatform>neutral</NativePlatform>
<NativePlatform Condition="'$(RuntimeIdentifier)' == 'win10-x86'">x86</NativePlatform>
<NativePlatform Condition="'$(RuntimeIdentifier)' == 'win10-x64'">x64</NativePlatform>
<NativePlatform Condition="'$(RuntimeIdentifier)' == 'win10-arm'">arm</NativePlatform>
<NativePlatform Condition="'$(RuntimeIdentifier)' == 'win10-arm64'">arm64</NativePlatform>
</PropertyGroup>
<ItemGroup>
<MicrosoftWindowsAppSDKMsix Include="$([MSBuild]::NormalizeDirectory('$(MicrosoftWindowsAppSDKPackageDir)','tools\Msix\win10-$(NativePlatform)'))Microsoft.WindowsAppRuntime.?.?.Msix"/>
<MicrosoftWindowsAppSDKMsix Include="$([MSBuild]::NormalizeDirectory('$(MicrosoftWindowsAppSDKPackageDir)','tools\Msix\win10-$(NativePlatform)'))Microsoft.WindowsAppRuntime.?.?-*.Msix"/>
</ItemGroup>
</Target>

</Project>
30 changes: 30 additions & 0 deletions src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs
Expand Up @@ -149,6 +149,36 @@ public void BuildUnpackaged(string id, string framework, string config)
$"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)
{
if (TestEnvironment.IsMacOS)
Assert.Ignore("This test is designed for testing a windows build.");

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

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

FileUtilities.ReplaceInFile(projectFile,
"<UseMaui>true</UseMaui>",
$"""
<UseMaui>true</UseMaui>
<WindowsAppSDKSelfContained>{wasdkself}</WindowsAppSDKSelfContained>
<SelfContained>{netself}</SelfContained>
""");

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

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

[Test]
[TestCase("maui", $"{DotNetCurrent}-ios", "ios-arm64")]
public void PublishNativeAOT(string id, string framework, string runtimeIdentifier)
Expand Down

0 comments on commit ff0aea3

Please sign in to comment.