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

Enable building WASDK Self-Contained packaged apps #20019

Merged
merged 1 commit into from Jan 24, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>
Expand Up @@ -113,6 +113,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