Skip to content

Commit

Permalink
feat: Add support for multiple output merged files (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Apr 7, 2022
1 parent a3e40c0 commit c646cbd
Show file tree
Hide file tree
Showing 35 changed files with 814 additions and 176 deletions.
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -57,6 +57,24 @@ Otherwise, the generated file can be referenced as follows:
</ResourceDictionary>
```

## Multiple generated files
There are scenarios where placing groups of XAML files in separate merged file are useful, particularly when IL Linking must be used.

In this case, the project file must be defined as follows:
```xml
<ItemGroup>
<!-- Output files -->
<XamlMergeOutputFiles Include="Generated\MergedPart1.xaml" />
<XamlMergeOutputFiles Include="Generated\MergedPart2.xaml" />

<!-- Input files, with the `MergeFile` metadata -->
<XamlMergeInput Include="Styles\Part1\**\*.xaml" Exclude="Styles\Generic.xaml" MergeFile="MergedPart1.xaml" />
<XamlMergeInput Include="Styles\Part2\**\*.xaml" Exclude="Styles\Generic.xaml" MergeFile="MergedPart2.xaml" />
</ItemGroup>
```

In this case, the `XamlMergeOutputFile` cannot be used, as the `XamlMergeOutputFiles` is defined.

## Troubleshooting
- Make sure that all namespaces definitions across files are of the same values. (e.g. `xlmns:ns1="http://site1"` and `xlmns:ns1="http://site2"` in two different files will fail)
- If you include the same resource dictionary (e.g. Colors.xaml) file in multiple merged files (generally used to have a file for custom brushes and colors), you can remove those multiple inclusions.
1 change: 1 addition & 0 deletions src/UWP/TestLibrary/Generated/mergedpages02.xaml
@@ -0,0 +1 @@
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />
80 changes: 41 additions & 39 deletions src/UWP/TestLibrary/TestLibrary.csproj
@@ -1,48 +1,50 @@
<Project Sdk="MSBuild.Sdk.Extras/3.0.23">
<!--
<!--
Adding project references to this project requires some manual adjustments.
Please see https://github.com/unoplatform/uno/issues/3909 for more details.
-->
<PropertyGroup>
<TargetFrameworks>uap10.0.19041;netstandard2.0;net6.0-ios;net6.0-macos;net6.0-maccatalyst;net6.0-android</TargetFrameworks>
<!-- Ensures the .xr.xml files are generated in a proper layout folder -->
<GenerateLibraryLayout>true</GenerateLibraryLayout>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Uno.UI" Version="4.0.13" />
</ItemGroup>
<ItemGroup>
<Page Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml" />
<Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml" />
</ItemGroup>
<ItemGroup>
<Page Update="Inner1\ImplicitConflict.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Inner1\Colors.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Inner1\_test.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Inner1\ResourceDictionary2.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="ResourceDictionary1.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Themes\Generic.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<PropertyGroup>
<TargetFrameworks>uap10.0.19041;netstandard2.0;net6.0-ios;net6.0-macos;net6.0-maccatalyst;net6.0-android</TargetFrameworks>
<!-- Ensures the .xr.xml files are generated in a proper layout folder -->
<GenerateLibraryLayout>true</GenerateLibraryLayout>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Uno.UI" Version="4.0.13" />
</ItemGroup>
<ItemGroup>
<Page Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml" />
<Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml" />
</ItemGroup>
<ItemGroup>
<Page Update="Inner1\ImplicitConflict.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Inner1\Colors.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Inner1\_test.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Inner1\ResourceDictionary2.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="ResourceDictionary1.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Themes\Generic.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>

<ItemGroup>
<XamlMergeInput Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml;Themes\Generic.xaml" />
<XamlMergeOutputFiles Include="Generated\mergedpages01.xaml"/>
<XamlMergeOutputFiles Include="Generated\mergedpages02.xaml"/>
<XamlMergeInput Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml;Themes\Generic.xaml" MergeFile="mergedpages01.xaml" />
</ItemGroup>

<Import Project="..\..\Uno.XamlMerge.Task\build\Uno.XamlMerge.Task.targets" />
Expand Down
38 changes: 38 additions & 0 deletions src/UWP/TestLibrarySingleFile/Generated/mergedpages.xaml
@@ -0,0 +1,38 @@
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:TestLibrary" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d xamarin ios android macos wasm skia" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:xamarin="http://uno.ui/xamarin" xmlns:android="http://uno.ui/android" xmlns:ios="http://uno.ui/ios" xmlns:wasm="http://uno.ui/wasm" xmlns:macos="http://uno.ui/macos" xmlns:skia="http://uno.ui/skia" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///TestLibrary/Colors.xaml" />
</ResourceDictionary.MergedDictionaries>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<Color x:Key="SystemColorHighlightColor">#FF3399FF</Color>
<ios:FontFamily x:Key="SymbolThemeFontFamily">Symbols</ios:FontFamily>
<macos:FontFamily x:Key="SymbolThemeFontFamily">Symbols</macos:FontFamily>
<wasm:FontFamily x:Key="SymbolThemeFontFamily">Symbols</wasm:FontFamily>
<skia:FontFamily x:Key="SymbolThemeFontFamily">ms-appx:///Assets/Fonts/uno-fluentui-assets.ttf#Symbols</skia:FontFamily>
<android:FontFamily x:Key="SymbolThemeFontFamily">ms-appx:///Assets/Fonts/uno-fluentui-assets.ttf#Symbols</android:FontFamily>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<!--origin: Inner1\Colors.xaml-->
<x:String x:Key="TestLibrary_String02">TestLibrary String 02</x:String>
<!--origin: Inner1\ImplicitConflict.xaml-->
<Style x:Key="Button" TargetType="TextBlock">
<Setter Property="FontSize" Value="12" />
</Style>
<Style TargetType="Button">
<Setter Property="FontSize" Value="24" />
</Style>
<!--origin: Inner1\ResourceDictionary2.xaml-->
<xamarin:Style TargetType="ItemsControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ItemsControl">
<ItemsPresenter Padding="{TemplateBinding Padding}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</xamarin:Style>
<x:String x:Key="TestLibrary_String03">TestLibrary String 02</x:String>
<!--origin: Inner1\_test.xaml-->
<!--origin: ResourceDictionary1.xaml-->
<x:String x:Key="TestLibrary_String">TestLibrary String</x:String>
</ResourceDictionary>
8 changes: 8 additions & 0 deletions src/UWP/TestLibrarySingleFile/Inner1/Colors.xaml
@@ -0,0 +1,8 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestLibrary">

<x:String x:Key="TestLibrary_String02">TestLibrary String 02</x:String>

</ResourceDictionary>
16 changes: 16 additions & 0 deletions src/UWP/TestLibrarySingleFile/Inner1/ImplicitConflict.xaml
@@ -0,0 +1,16 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestLibrary">

<Style x:Key="Button"
TargetType="TextBlock">
<Setter Property="FontSize"
Value="12" />
</Style>
<Style TargetType="Button">
<Setter Property="FontSize"
Value="24" />
</Style>

</ResourceDictionary>
42 changes: 42 additions & 0 deletions src/UWP/TestLibrarySingleFile/Inner1/ResourceDictionary2.xaml
@@ -0,0 +1,42 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestLibrary"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:xamarin="http://uno.ui/xamarin"
xmlns:android="http://uno.ui/android"
xmlns:ios="http://uno.ui/ios"
xmlns:wasm="http://uno.ui/wasm"
xmlns:macos="http://uno.ui/macos"
xmlns:skia="http://uno.ui/skia"
mc:Ignorable="d xamarin ios android macos wasm skia xamarin">

<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<!-- Added manually (not part of UWP's SystemResources.xaml) -->
<Color x:Key="SystemColorHighlightColor">#FF3399FF</Color>

<ios:FontFamily x:Key="SymbolThemeFontFamily">Symbols</ios:FontFamily>
<macos:FontFamily x:Key="SymbolThemeFontFamily">Symbols</macos:FontFamily>
<wasm:FontFamily x:Key="SymbolThemeFontFamily">Symbols</wasm:FontFamily>
<skia:FontFamily x:Key="SymbolThemeFontFamily">ms-appx:///Assets/Fonts/uno-fluentui-assets.ttf#Symbols</skia:FontFamily>
<android:FontFamily x:Key="SymbolThemeFontFamily">ms-appx:///Assets/Fonts/uno-fluentui-assets.ttf#Symbols</android:FontFamily>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>

<x:String x:Key="TestLibrary_String02">TestLibrary String 02</x:String>

<!-- TODO: ItemsControl should inject ItemsPresenter directly if no template is found. (Change this once template is materialized on Measure) -->
<xamarin:Style TargetType="ItemsControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ItemsControl">
<ItemsPresenter Padding="{TemplateBinding Padding}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</xamarin:Style>

<x:String x:Key="TestLibrary_String03">TestLibrary String 02</x:String>

</ResourceDictionary>
10 changes: 10 additions & 0 deletions src/UWP/TestLibrarySingleFile/Inner1/_test.xaml
@@ -0,0 +1,10 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestLibrary">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///TestLibrary/Colors.xaml" />
</ResourceDictionary.MergedDictionaries>

</ResourceDictionary>
8 changes: 8 additions & 0 deletions src/UWP/TestLibrarySingleFile/ResourceDictionary1.xaml
@@ -0,0 +1,8 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestLibrary">

<x:String x:Key="TestLibrary_String">TestLibrary String</x:String>

</ResourceDictionary>
61 changes: 61 additions & 0 deletions src/UWP/TestLibrarySingleFile/TestLibrarySingleFile.csproj
@@ -0,0 +1,61 @@
<Project Sdk="MSBuild.Sdk.Extras/3.0.23">
<!--
Adding project references to this project requires some manual adjustments.
Please see https://github.com/unoplatform/uno/issues/3909 for more details.
-->
<PropertyGroup>
<TargetFrameworks>uap10.0.19041;netstandard2.0;net6.0-ios;net6.0-macos;net6.0-maccatalyst;net6.0-android</TargetFrameworks>
<!-- Ensures the .xr.xml files are generated in a proper layout folder -->
<GenerateLibraryLayout>true</GenerateLibraryLayout>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Uno.UI" Version="4.0.13" />
</ItemGroup>
<ItemGroup>
<Page Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml" />
<Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml" />
</ItemGroup>
<ItemGroup>
<Page Update="Inner1\ImplicitConflict.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Inner1\Colors.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Inner1\_test.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Inner1\ResourceDictionary2.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="ResourceDictionary1.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Themes\Generic.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>

<ItemGroup>
<XamlMergeInput Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml;Themes\Generic.xaml" />
</ItemGroup>

<Import Project="..\..\Uno.XamlMerge.Task\build\Uno.XamlMerge.Task.targets" />

<ItemGroup>
<ProjectReference Include="..\..\Uno.XamlMerge.Task\Uno.XamlMerge.Task.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
<UndefineProperties>TargetFramework</UndefineProperties>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<Folder Include="Generated\" />
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions src/UWP/TestLibrarySingleFile/Themes/Generic.xaml
@@ -0,0 +1,12 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestLibrary">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///TestLibrary/Generated/mergedpages.xaml" />

</ResourceDictionary.MergedDictionaries>

<x:String x:Key="test01">test01</x:String>
</ResourceDictionary>

0 comments on commit c646cbd

Please sign in to comment.