Skip to content

Commit

Permalink
fix: Always run generation on build (#112)
Browse files Browse the repository at this point in the history
* chore: Add net6 winui template validation

* fix: Always run generation on build

Avoids skipped generation on forced targetframework, which can happen when a build is performed through VS's Debug button on multi-targeted projects, or using `-f` on the CLI.

* ci: adjust samples tests to remove window target

* ci: Adjust build options
  • Loading branch information
jeromelaban committed Jan 12, 2023
1 parent c86c94b commit 981a35b
Show file tree
Hide file tree
Showing 127 changed files with 2,902 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -104,7 +104,7 @@ jobs:
- name: Validate Test Projects
run: |
$msbuild = vswhere -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe
& $msbuild /m /nr:false /r /p:Configuration=Release src\Uno.XamlMerge.Task.sln /p:AppxPackageSigningEnabled=false
& $msbuild /m /nr:false /r /p:Configuration=Release build\Uno.XamlMerge.Task-ci-only.slnf /p:AppxPackageSigningEnabled=false /p:AotAssemblies=false /p:WasmShellILLinkerEnabled=false
publish:
name: Publish
Expand Down
22 changes: 22 additions & 0 deletions build/Uno.XamlMerge.Task-ci-only.slnf
@@ -0,0 +1,22 @@
{
"solution": {
"path": "..\\src\\Uno.XamlMerge.Task.sln",
"projects": [
"UWP\\TestLibrarySingleFile\\TestLibrarySingleFile.csproj",
"UWP\\TestLibrary\\TestLibrary.csproj",
"UWP\\XamlMergeUWPTest\\XamlMergeUWPTest.Droid\\XamlMergeUWPTest.Droid.csproj",
"UWP\\XamlMergeUWPTest\\XamlMergeUWPTest.Shared\\XamlMergeUWPTest.Shared.shproj",
"UWP\\XamlMergeUWPTest\\XamlMergeUWPTest.Skia.Gtk\\XamlMergeUWPTest.Skia.Gtk.csproj",
"UWP\\XamlMergeUWPTest\\XamlMergeUWPTest.UWP\\XamlMergeUWPTest.UWP.csproj",
"UWP\\XamlMergeUWPTest\\XamlMergeUWPTest.Wasm\\XamlMergeUWPTest.Wasm.csproj",
"UWP\\XamlMergeUWPTest\\XamlMergeUWPTest.iOS\\XamlMergeUWPTest.iOS.csproj",
"Uno.XamlMerge.Task\\Uno.XamlMerge.Task.csproj",
"Uno.XamlMerge.Tests\\Uno.XamlMerge.Tests.csproj",
"WinUI\\TestLibraryWinUI\\TestLibraryWinUI.csproj",
"WinUI\\XamlMergeWinUITest.Mobile\\XamlMergeWinUITest.Mobile.csproj",
"WinUI\\XamlMergeWinUITest.Shared\\XamlMergeWinUITest.Shared.shproj",
"WinUI\\XamlMergeWinUITest.Skia.Gtk\\XamlMergeWinUITest.Skia.Gtk.csproj",
"WinUI\\XamlMergeWinUITest.Wasm\\XamlMergeWinUITest.Wasm.csproj"
]
}
}
334 changes: 334 additions & 0 deletions src/Uno.XamlMerge.Task.sln

Large diffs are not rendered by default.

47 changes: 33 additions & 14 deletions src/Uno.XamlMerge.Task/Utils.cs
Expand Up @@ -6,6 +6,7 @@
#nullable disable

using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;
Expand Down Expand Up @@ -37,26 +38,44 @@ public static string DocumentToString(Action<XmlWriter> action)

public static string RewriteFileIfNecessary(string path, string contents)
{
bool rewrite = true;
var fullPath = Path.GetFullPath(path);
try
var sw = Stopwatch.StartNew();
Exception lastException = null;

while (sw.Elapsed < TimeSpan.FromSeconds(3))
{
string existingContents = File.ReadAllText(fullPath);
if (String.Equals(existingContents, contents))
try
{
rewrite = false;
bool rewrite = true;
var fullPath = Path.GetFullPath(path);
try
{
string existingContents = File.ReadAllText(fullPath);
if (String.Equals(existingContents, contents))
{
rewrite = false;
}
}
catch
{
}

if (rewrite)
{
File.WriteAllText(fullPath, contents);
}

return fullPath;
}
}
catch
{
}
catch(Exception e)
{
lastException = e;

if (rewrite)
{
File.WriteAllText(fullPath, contents);
// Retry on any exception
Thread.Sleep(250);
}
}

return fullPath;
throw new InvalidOperationException($"Failed to write file {path}: {lastException}");
}
}
}
2 changes: 1 addition & 1 deletion src/Uno.XamlMerge.Task/build/Uno.XamlMerge.Task.targets
Expand Up @@ -10,7 +10,7 @@
<Target Name="GenerateMergedXaml"
BeforeTargets="_ComputeTargetFrameworkItems;BeforeBuild;GenerateMSBuildEditorConfigFileCore;_InjectAdditionalFiles"
DependsOnTargets="_XamlMergeFillProperties"
Condition="('$(TargetFramework)' == '' or '$(TargetFrameworks)'=='') and ('$(BuildingProject)' == 'true' or '$(DesignTimeBuild)' != 'true')">
Condition="'$(BuildingProject)' == 'true' or '$(DesignTimeBuild)' != 'true'">

<BatchMergeXaml_v0
ProjectFullPath="$(MSBuildProjectFullPath)"
Expand Down
11 changes: 11 additions & 0 deletions src/WinUI/TestLibraryWinUI/Class1.cs
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestLibraryWinUI
{
public class Class1
{
}
}
8 changes: 8 additions & 0 deletions src/WinUI/TestLibraryWinUI/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/WinUI/TestLibraryWinUI/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/WinUI/TestLibraryWinUI/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/WinUI/TestLibraryWinUI/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/WinUI/TestLibraryWinUI/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>
46 changes: 46 additions & 0 deletions src/WinUI/TestLibraryWinUI/TestLibraryWinUI.csproj
@@ -0,0 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0-windows10.0.18362;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 Condition="'$(TargetFramework)'=='net6.0-windows10.0.18362'">
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.3" />
<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" RuntimeFrameworkVersion="10.0.22000.24" />
<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.22000.24" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'!='net6.0-windows10.0.18362'">
<PackageReference Include="Uno.WinUI" Version="4.6.19" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'!='net6.0-windows10.0.18362'">
<Content Include="Assets\**" />
<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>
<XamlMergeOutputFiles Include="$(BaseIntermediateOutputPath)\Generated\mergedpages01.xaml" />
<XamlMergeOutputFiles Include="$(BaseIntermediateOutputPath)\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" />

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

</Project>
12 changes: 12 additions & 0 deletions src/WinUI/TestLibraryWinUI/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,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.companyname.XamlMergeWinUITest" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<application android:label="XamlMergeWinUITest"></application>
</manifest>
22 changes: 22 additions & 0 deletions src/WinUI/XamlMergeWinUITest.Mobile/Android/Assets/AboutAssets.txt
@@ -0,0 +1,22 @@
To add cross-platform image assets for your Uno Platform app, use the Assets folder
in the shared project instead. Assets in this folder are Android-only assets.

Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".

These files will be deployed with you package and will be accessible using Android's
AssetManager, like this:

public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

InputStream input = Assets.Open ("my_asset.txt");
}
}

Additionally, some Android functions will automatically load asset files:

Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Binary file not shown.
43 changes: 43 additions & 0 deletions src/WinUI/XamlMergeWinUITest.Mobile/Android/Main.Android.cs
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Com.Nostra13.Universalimageloader.Core;
using Microsoft.UI.Xaml.Media;

namespace XamlMergeWinUITest.Droid
{
[global::Android.App.ApplicationAttribute(
Label = "@string/ApplicationName",
Icon = "@mipmap/icon",
LargeHeap = true,
HardwareAccelerated = true,
Theme = "@style/AppTheme"
)]
public class Application : Microsoft.UI.Xaml.NativeApplication
{
public Application(IntPtr javaReference, JniHandleOwnership transfer)
: base(() => new App(), javaReference, transfer)
{
ConfigureUniversalImageLoader();
}

private static void ConfigureUniversalImageLoader()
{
// Create global configuration and initialize ImageLoader with this config
ImageLoaderConfiguration config = new ImageLoaderConfiguration
.Builder(Context)
.Build();

ImageLoader.Instance.Init(config);

ImageSource.DefaultImageLoader = ImageLoader.Instance.LoadImageAsync;
}
}
}
@@ -0,0 +1,18 @@
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Content.PM;
using Android.Views;

namespace XamlMergeWinUITest
{
[Activity(
MainLauncher = true,
ConfigurationChanges = global::Uno.UI.ActivityHelper.AllConfigChanges,
WindowSoftInputMode = SoftInput.AdjustPan | SoftInput.StateHidden
)]
public class MainActivity : Microsoft.UI.Xaml.ApplicationActivity
{
}
}

0 comments on commit 981a35b

Please sign in to comment.