Skip to content

Commit 120e615

Browse files
authored
Fix the WAP packaging project (#1900)
* Fix the WAP packaging project This commits fixes the centennial package by: * Forcing XBF (XAML binary format) files to be embedded in project PRI files. * Moving package content generation to before PRI generation * Collecting all of the package's PRI files to merge into resources.pri * Fixing the hardcoded resource paths to reflect the new reality. It also includes a magic value that fixes the bug where the project is autodetected as a Mixed (CLR + Native) project. Fixes #1816.
1 parent c159924 commit 120e615

File tree

5 files changed

+54
-31
lines changed

5 files changed

+54
-31
lines changed

src/cascadia/CascadiaPackage/CascadiaPackage.wapproj

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<PropertyGroup>
2323
<ProjectGuid>CA5CAD1A-224A-4171-B13A-F16E576FDD12</ProjectGuid>
2424
<EntryPointProjectUniqueName>..\WindowsTerminal\WindowsTerminal.vcxproj</EntryPointProjectUniqueName>
25+
<DebuggerType>NativeOnly</DebuggerType>
2526
</PropertyGroup>
2627
<PropertyGroup Condition="!Exists('CascadiaPackage_TemporaryKey.pfx')">
2728
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
@@ -260,12 +261,11 @@
260261
</ItemGroup>
261262
<Import Project="$(OpenConsoleDir)src\wap-common.build.post.props" />
262263
<!--
263-
This exists to work around Microsoft/microsoft-ui-xaml#494.
264-
https://github.com/Microsoft/microsoft-ui-xaml/issues/494
264+
Microsoft.UI.Xaml contains some <Content> resource files that need to be included in our package.
265+
For some reason, they're not rolled up through dependent projects; if they were, their paths would
266+
be wrong.
265267
266-
Because the MUX nuget package hardcodes a requirement that the consuming project
267-
be of type 'UAP', its resources are included in packaging and dependency resolution
268-
by default. Inject them here.
268+
WAP Packaging projects don't actually support nuget package references, so we added one manually.
269269
270270
This does mean that version changes to Microsoft.UI.Xaml must be manually reflected
271271
here.
@@ -277,17 +277,6 @@
277277
</PropertyGroup>
278278
<Error Condition="!Exists('..\..\..\packages\Microsoft.UI.Xaml.2.2.190611001-prerelease\build\native\Microsoft.UI.Xaml.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.UI.Xaml.2.2.190611001-prerelease\build\native\Microsoft.UI.Xaml.targets'))" />
279279
</Target>
280-
<PropertyGroup>
281-
<WapProjBeforeGenerateAppxManifestDependsOn>
282-
$(WapProjBeforeGenerateAppxManifestDependsOn);
283-
_ConsoleInjectMUXWinmdIntoReferences;
284-
</WapProjBeforeGenerateAppxManifestDependsOn>
285-
</PropertyGroup>
286-
<Target Name="_ConsoleInjectMUXWinmdIntoReferences">
287-
<ItemGroup>
288-
<_WinmdFilesFromReferences Include="@(Reference)" Condition="'%(Reference.Filename)' == 'Microsoft.UI.Xaml' and '%(Reference.Extension)' == '.winmd'" />
289-
</ItemGroup>
290-
</Target>
291280
<!-- End workaround -->
292281
<ItemGroup>
293282
<ProjectReference Include="..\WindowsTerminal\WindowsTerminal.vcxproj" />
@@ -310,4 +299,25 @@
310299
</_FilteredNonWapProjProjectOutput>
311300
</ItemGroup>
312301
</Target>
302+
303+
<!-- Move all the PRI files that would be packaged into the appx into _PriFile so that
304+
GenerateProjectPriFile catches them. This requires us to move payload collection
305+
up before GenerateProjectPriFile, when it is typically _after_ it (because the
306+
DesktopBridge project type is built to only prepare the payload during appx manifest
307+
generation.
308+
309+
Since PRI file generation is _before_ manifest generation (for possibly obvious or
310+
important reasons), that doesn't work for us.
311+
-->
312+
<PropertyGroup>
313+
<_GenerateProjectPriFileDependsOn>OpenConsoleLiftDesktopBridgePriFiles;$(_GenerateProjectPriFileDependsOn)</_GenerateProjectPriFileDependsOn>
314+
</PropertyGroup>
315+
<Target Name="OpenConsoleLiftDesktopBridgePriFiles" DependsOnTargets="_ConvertItems">
316+
<ItemGroup>
317+
<_PriFile Include="@(_NonWapProjProjectOutput)" Condition="'%(Extension)' == '.pri'" />
318+
<!-- Remove all other .pri files from the appx payload. -->
319+
<AppxPackagePayload Remove="@(AppxPackagePayload)" Condition="'%(Extension)' == '.pri'" />
320+
</ItemGroup>
321+
</Target>
322+
313323
</Project>

src/cascadia/TerminalApp/MinMaxCloseControl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ namespace winrt::TerminalApp::implementation
1313
{
1414
MinMaxCloseControl::MinMaxCloseControl()
1515
{
16-
const winrt::Windows::Foundation::Uri resourceLocator{ L"ms-appx:///MinMaxCloseControl.xaml" };
17-
winrt::Windows::UI::Xaml::Application::LoadComponent(*this, resourceLocator, winrt::Windows::UI::Xaml::Controls::Primitives::ComponentResourceLocation::Nested);
16+
InitializeComponent();
1817
}
1918

2019
uint64_t MinMaxCloseControl::ParentWindowHandle() const

src/cascadia/TerminalApp/TerminalApp.vcxproj

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
<ProjectGuid>{CA5CAD1A-44BD-4AC7-AC72-F16E576FDD12}</ProjectGuid>
1616
<ProjectName>TerminalApp</ProjectName>
1717
<RootNamespace>TerminalApp</RootNamespace>
18+
<!--
19+
This is an override that, puzzlingly, _forces XBF (XAML binary) embedding_.
20+
We have to do this to overcome a layout issue in the WAP packaging project.
21+
When we do this, the XBF ends up in resources.pri.
22+
-->
23+
<DisableEmbeddedXbf>false</DisableEmbeddedXbf>
1824
</PropertyGroup>
1925
<!-- ========================= XAML files ======================== -->
2026
<ItemGroup>
@@ -166,4 +172,24 @@
166172
<Error Condition="!Exists('..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.0.0-preview6.2\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.0.0-preview6.2\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.targets'))" />
167173
</Target>
168174
<Import Project="..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.0.0-preview6.2\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.targets" Condition="Exists('..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.0.0-preview6.2\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.targets')" />
175+
176+
<!--
177+
By default, the PRI file will contain resource paths beginning with the
178+
project name. Since we enabled XBF embedding, this *also* includes App.xbf.
179+
Well, App.xbf is hardcoded by the framework to be found at the resource ROOT.
180+
To make that happen, we have to disable the prepending of the project name
181+
to the App xaml files.
182+
-->
183+
<PropertyGroup>
184+
<_GenerateProjectPriFileDependsOn>OpenConsolePlaceAppXbfAtRootOfResourceTree;$(_GenerateProjectPriFileDependsOn)</_GenerateProjectPriFileDependsOn>
185+
</PropertyGroup>
186+
<Target Name="OpenConsolePlaceAppXbfAtRootOfResourceTree" DependsOnTargets="GetPackagingOutputs">
187+
<ItemGroup>
188+
<_RelocatedAppXamlData Include="@(PackagingOutputs)" Condition="'%(Filename)' == 'App' and ('%(Extension)' == '.xaml' or '%(Extension)' == '.xbf')" />
189+
<PackagingOutputs Remove="@(_RelocatedAppXamlData)" />
190+
<PackagingOutputs Include="@(_RelocatedAppXamlData)">
191+
<TargetPath>%(Filename)%(Extension)</TargetPath>
192+
</PackagingOutputs>
193+
</ItemGroup>
194+
</Target>
169195
</Project>

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ namespace winrt::TerminalApp::implementation
1313
{
1414
TerminalPage::TerminalPage()
1515
{
16-
// The generated code will by default attempt to load from ms-appx://TerminalApp/TerminalPage.xaml.
17-
// We'll force it to load from the root of the appx instead.
18-
const winrt::Windows::Foundation::Uri resourceLocator{ L"ms-appx:///TerminalPage.xaml" };
19-
winrt::Windows::UI::Xaml::Application::LoadComponent(*this, resourceLocator, winrt::Windows::UI::Xaml::Controls::Primitives::ComponentResourceLocation::Nested);
16+
InitializeComponent();
2017
}
2118

2219
// Method Description:

src/cascadia/WindowsTerminal/WindowsTerminal.vcxproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,6 @@
9191
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9292
</NativeReferenceFile>
9393

94-
<!--
95-
The reason why this is needed for ARM64 is unknown,
96-
If not added, the centenial package will fail to include the XamlHost dll.
97-
-->
98-
<NativeReferenceFile Include="$(OpenConsoleDir)$(Platform)\$(Configuration)\TerminalApp\Microsoft.Toolkit.Win32.UI.XamlHost.dll" Condition="'$(Platform)'=='ARM64'">
99-
<DeploymentContent>true</DeploymentContent>
100-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
101-
</NativeReferenceFile>
102-
10394
<!--
10495
the packaging project wont recurse through our dependencies, you have to
10596
make sure that if you add a cppwinrt dependency to any of these projects,

0 commit comments

Comments
 (0)