Skip to content

Commit

Permalink
Merge pull request #75 from CommunityToolkit/feature/winui-2-and-3
Browse files Browse the repository at this point in the history
Add support for both WinUI 2 and 3 under Uno platform
  • Loading branch information
michael-hawker authored Apr 20, 2022
2 parents 7326f73 + a82bf2a commit 6ed4315
Show file tree
Hide file tree
Showing 24 changed files with 313 additions and 112 deletions.
106 changes: 96 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,81 @@ on:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# This workflow contains a single job called "Build-WinUI-2"
Build-WinUI-2:
# The type of runner that the job will run on
runs-on: windows-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Needed until XAML Styler updates to .NET 6
- name: Install .NET Core 3.1 SDK
- name: Install .NET 6 SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'
dotnet-version: '6.0.201'

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout Repository
uses: actions/checkout@v2

# Restore Tools from Manifest list in the Repository
- name: Restore dotnet tools
run: dotnet tool restore

- name: Run Uno Check to Install Dependencies
run: dotnet tool run uno-check --ci --fix --non-interactive --skip wsl --skip androidemulator --verbose

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.3

- name: Enable all TargetFrameworks
working-directory: ./common/Scripts/
run: ./UseTargetFrameworks.ps1 all

- name: MSBuild
# working-directory: ./
run: msbuild.exe Toolkit.Labs.All.sln /restore -p:Configuration=Release

# Build All Packages - TODO: Detect experiments
- name: pack CanvasLayout
working-directory: ./labs/CanvasLayout/src
run: msbuild -t:pack /p:Configuration=Release /p:DebugType=Portable

# Push Packages to our DevOps Artifacts Feed
- name: Add source
run: dotnet nuget add source "https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-Labs/nuget/v3/index.json" --name LabsFeed --username dummy --password ${{ secrets.DEVOPS_PACKAGE_PUSH_TOKEN }}

- name: Push packages
if: ${{github.ref == 'refs/heads/main'}}
run: dotnet nuget push "**/*.nupkg" --api-key dummy --source LabsFeed --skip-duplicate

# Run tests
- name: Setup VSTest Path
uses: darenm/Setup-VSTest@v1

- name: Run SourceGenerators tests
run: vstest.console.exe ./Common/CommunityToolkit.Labs.Core.SourceGenerators.Tests/CommunityToolkit.Labs.Core.SourceGenerators.Tests/bin/Release/net6.0/CommunityToolkit.Labs.Core.SourceGenerators.Tests.dll /logger:"trx;LogFileName=SourceGenerators.trx"

- name: Run experiment tests against UWP
run: vstest.console.exe ./Tests/**/CommunityToolkit.Labs.UnitTests.UWP.build.appxrecipe /Framework:FrameworkUap10 /logger:"trx;LogFileName=UWP.trx"

- name: Run experiment tests against WinAppSDK
run: vstest.console.exe ./Tests/**/CommunityToolkit.Labs.UnitTests.WinAppSdk.build.appxrecipe /Framework:FrameworkUap10 /logger:"trx;LogFileName=WinAppSdk.trx"

- name: Create test reports
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if previous step failed
with:
name: Test results
path: './TestResults/*.trx'
reporter: dotnet-trx

# This workflow contains a single job called "Build-WinUI-3"
Build-WinUI-3:
# The type of runner that the job will run on
runs-on: windows-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Install .NET 6 SDK
uses: actions/setup-dotnet@v1
with:
Expand All @@ -43,11 +105,8 @@ jobs:
- name: Restore dotnet tools
run: dotnet tool restore

- name: Check XAML Styling
run: ./ApplyXamlStyling.ps1 -Passive

- name: Run Uno Check to Install Dependencies
run: dotnet tool run uno-check --ci --fix --non-interactive --skip wsl --skip androidemulator #--verbose
run: dotnet tool run uno-check --ci --fix --non-interactive --skip wsl --skip androidemulator --verbose

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.3
Expand All @@ -56,6 +115,10 @@ jobs:
working-directory: ./common/Scripts/
run: ./UseTargetFrameworks.ps1 all

- name: Enable WinUI 3
working-directory: ./common/Scripts/
run: ./UseUnoWinUI.ps1 3

- name: MSBuild
# working-directory: ./
run: msbuild.exe Toolkit.Labs.All.sln /restore -p:Configuration=Release
Expand All @@ -73,7 +136,6 @@ jobs:
if: ${{github.ref == 'refs/heads/main'}}
run: dotnet nuget push "**/*.nupkg" --api-key dummy --source LabsFeed --skip-duplicate


# Run tests
- name: Setup VSTest Path
uses: darenm/Setup-VSTest@v1
Expand All @@ -94,6 +156,30 @@ jobs:
name: Test results
path: './TestResults/*.trx'
reporter: dotnet-trx

# This workflow contains a single job called "Xaml-Style-Check"
Xaml-Style-Check:
# The type of runner that the job will run on
runs-on: windows-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Needed until XAML Styler updates to .NET 6
- name: Install .NET Core 3.1 SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout Repository
uses: actions/checkout@v2

# Restore Tools from Manifest list in the Repository
- name: Restore dotnet tools
run: dotnet tool restore

- name: Check XAML Styling
run: ./ApplyXamlStyling.ps1 -Passive

# Test/temp job to build a single experiment to ensure our changes work for both our main types of solutions at the moment
experiment:
Expand Down
39 changes: 8 additions & 31 deletions common/CommunityToolkit.Labs.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,50 +56,27 @@ public App()
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Frame? rootFrame = null;

#if WINAPPSDK
var window = new Window();
#else
rootFrame = currentWindow.Content as Frame;
currentWindow = new Window();
#endif

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
if (currentWindow.Content is not Frame rootFrame)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
currentWindow.Content = rootFrame = new Frame();

rootFrame.NavigationFailed += OnNavigationFailed;

#if WINAPPSDK
window.Content = rootFrame;
#else
// Place the frame in the current Window
currentWindow.Content = rootFrame;
#endif
}


#if WINAPPSDK
rootFrame.Navigate(typeof(AppLoadingView), e.Arguments);
window.Activate();
#else
#if !WINAPPSDK
if (e.PrelaunchActivated == false)
{
if (rootFrame is null)
throw new InvalidOperationException("Cannot display app content, root frame is missing.");

if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(AppLoadingView), e.Arguments);
}

// Ensure the current window is active
currentWindow.Activate();
}
#endif
rootFrame.Navigate(typeof(AppLoadingView), e.Arguments);

// Ensure the current window is active
currentWindow.Activate();
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion common/Labs.Head.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!-- Common props for any deployable sample project head. -->
<Project>

<!-- Shared project -->
<Import Project="$(RepositoryDirectory)\common\CommunityToolkit.Labs.Shared\CommunityToolkit.Labs.Shared.projitems" Label="Shared" />

Expand Down
19 changes: 4 additions & 15 deletions common/Labs.MultiTarget.props
Original file line number Diff line number Diff line change
@@ -1,56 +1,45 @@
<Project InitialTargets="ValidateWinUITarget">
<Project>
<Import Project="Labs.TargetFrameworks.props" />
<Import Project="Labs.Uno.props" />

<PropertyGroup>
<WinUITarget Condition="'$(WinUITarget)' == ''">2.x</WinUITarget>

<!--
TargetFramework for WasmLibTargetFramework, WpfLibTargetFramework, and LinuxLibTargetFramework all use the same value.
This can't be removed during the evaluation phase without breaking things, so we omit them entirely
and use the value directly.
-->
<TargetFrameworks>
netstandard2.0;
$(NetStandardCommonTargetFramework);
$(UwpTargetFramework);
$(WinAppSdkTargetFramework);
$(MacOSLibTargetFramework);
$(iOSLibTargetFramework);
$(AndroidLibTargetFramework);
</TargetFrameworks>

<IsUno Condition="'$(TargetFramework)' != '$(UwpTargetFramework)' AND '$(TargetFramework)' != '$(WinAppSdkTargetFramework)'">True</IsUno>

<GenerateLibraryLayout>true</GenerateLibraryLayout>
<EnableDefaultPageItems>false</EnableDefaultPageItems>
<DefineConstants Condition="'$(TargetFramework)' == '$(WinAppSdkTargetFramework)'">WINAPPSDK</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == '$(WinAppSdkTargetFramework)'">$(DefineConstants);WINAPPSDK</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == '$(WinAppSdkTargetFramework)' OR '$(TargetFramework)' == '$(UwpTargetFramework)'">
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
</PropertyGroup>

<Target Name="ValidateWinUITarget" Condition="'$(IsUno)' == 'true'">
<Error Condition="'$(WinUITarget)' != '2.x' AND '$(WinUITarget)' != '3.x'" Text="Property 'WinUITarget' contained an invalid value '$(WinUITarget)'. A value of '2.x' or '3.x' is expected when building an Uno target." />
</Target>

<ItemGroup>
<!-- In release mode, UWP already emits the raw XAML files to the final app package (with some modifications). -->
<Content Condition="!('$(TargetFramework)' == '$(UwpTargetFramework)' AND '$(Configuration)' == 'Release')" Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml" />
<Content Include="**\*.cs" Exclude="bin\**\*.cs;obj\**\*.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Condition="'$(IsUno)' == 'True' AND '$(WinUITarget)' == '2.x'" Include="Uno.UI" Version="4.0.11" />
<PackageReference Condition="'$(IsUno)' == 'True' AND '$(WinUITarget)' == '3.x'" Include="Uno.WinUI" Version="4.0.11" />

<PackageReference Condition="'$(TargetFramework)' == '$(UwpTargetFramework)'" Include="Microsoft.UI.Xaml" Version="2.7.0" />
<PackageReference Condition="'$(TargetFramework)' == '$(WinAppSdkTargetFramework)'" Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
</ItemGroup>

<!-- Source generator props -->

<ItemGroup>
<ProjectReference Include="$(RepositoryDirectory)\common\CommunityToolkit.Labs.Core.SourceGenerators.XamlNamedPropertyRelay\CommunityToolkit.Labs.Core.SourceGenerators.XamlNamedPropertyRelay.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="True" />
Expand Down
9 changes: 7 additions & 2 deletions common/Labs.TargetFrameworks.All.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
<LinuxHeadTargetFramework>net5.0</LinuxHeadTargetFramework>
<WpfHeadTargetFramework>netcoreapp3.1</WpfHeadTargetFramework>

<WasmLibTargetFramework>netstandard2.0</WasmLibTargetFramework>
<LinuxLibTargetFramework>netstandard2.0</LinuxLibTargetFramework>
<AndroidLibTargetFramework>monoandroid11.0</AndroidLibTargetFramework>
<MacOSLibTargetFramework>xamarinmac20</MacOSLibTargetFramework>
<iOSLibTargetFramework>xamarinios10</iOSLibTargetFramework>

<!-- Used for comparison to current TargetFramework -->
<LinuxLibTargetFramework>netstandard2.0</LinuxLibTargetFramework>
<WasmLibTargetFramework>netstandard2.0</WasmLibTargetFramework>
<WpfLibTargetFramework>netstandard2.0</WpfLibTargetFramework>

<!-- Used for defining TargetFramework under platforms that need it -->
<NetStandardCommonTargetFramework>netstandard2.0</NetStandardCommonTargetFramework>
</PropertyGroup>
</Project>
9 changes: 7 additions & 2 deletions common/Labs.TargetFrameworks.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
<LinuxHeadTargetFramework>net5.0</LinuxHeadTargetFramework>
<WpfHeadTargetFramework>netcoreapp3.1</WpfHeadTargetFramework>

<WasmLibTargetFramework>netstandard2.0</WasmLibTargetFramework>





<!-- Used for comparison to current TargetFramework -->
<LinuxLibTargetFramework>netstandard2.0</LinuxLibTargetFramework>
<WasmLibTargetFramework>netstandard2.0</WasmLibTargetFramework>
<WpfLibTargetFramework>netstandard2.0</WpfLibTargetFramework>

<!-- Used for defining TargetFramework under platforms that need it -->
<NetStandardCommonTargetFramework>netstandard2.0</NetStandardCommonTargetFramework>
</PropertyGroup>
</Project>
47 changes: 47 additions & 0 deletions common/Labs.Uno.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Project>
<Import Project="Labs.TargetFrameworks.props" />

<PropertyGroup>
<IsWasmHead Condition="'$(IsWasmHead)' == '' AND '$(TargetFramework)' == '$(WasmHeadTargetFramework)'">True</IsWasmHead>
<IsWpfHead Condition="'$(IsWpfHead)' == '' AND '$(TargetFramework)' == '$(WpfHeadTargetFramework)'">True</IsWpfHead>
<IsGtkHead Condition="'$(IsGtkHead)' == '' AND '$(TargetFramework)' == '$(LinuxHeadTargetFramework)'">True</IsGtkHead>

<IsWasmLib Condition="'$(IsWasmLib)' == '' AND '$(TargetFramework)' == '$(WasmLibTargetFramework)'">True</IsWasmLib>
<IsWpfLib Condition="'$(IsWpfLib)' == '' AND '$(TargetFramework)' == '$(WpfLibTargetFramework)'">True</IsWpfLib>
<IsGtkLib Condition="'$(IsGtkLib)' == '' AND '$(TargetFramework)' == '$(LinuxLibTargetFramework)'">True</IsGtkLib>

<IsWasm Condition="'$(IsWasm)' == '' AND ('$(IsWasmHead)' == 'true' or '$(IsWasmLib)' == 'true')">True</IsWasm>
<IsWpf Condition="'$(IsWpf)' == '' AND ('$(IsWpfHead)' == 'true' or '$(IsWpfLib)' == 'true')">True</IsWpf>
<IsGtk Condition="'$(IsGtk)' == '' AND ('$(IsGtkHead)' == 'true' or '$(IsGtkLib)' == 'true')">True</IsGtk>

<IsDroid Condition="'$(IsDroid)' == '' AND '$(TargetFramework)' == '$(AndroidLibTargetFramework)'">True</IsDroid>
<IsMacOS Condition="'$(IsMacOS)' == '' AND '$(TargetFramework)' == '$(MacOSLibTargetFramework)'">True</IsMacOS>
<IsiOS Condition="'$(IsiOS)' == '' AND '$(TargetFramework)' == '$(iOSLibTargetFramework)'">True</IsiOS>

<IsUno Condition="'$(IsWasm)' == 'true' OR '$(IsWpf)' == 'true' OR '$(IsGtk)' == 'true' OR '$(IsDroid)' == 'true' OR '$(IsMacOS)' == 'true' OR '$(IsiOS)' == 'true'">True</IsUno>

<DefineConstants Condition="'$(IsUno)' == 'true'">$(DefineConstants);</DefineConstants>

<PackageIdVariant>Uwp</PackageIdVariant>
</PropertyGroup>

<ItemGroup Condition="'$(IsUno)' == 'true'">
<PackageReference Include="Uno.UI" Version="4.1.9" />
</ItemGroup>

<ItemGroup Condition="'$(IsWasm)' == 'true' OR '$(IsWpf)' == 'true' OR '$(IsGtk)' == 'true'">
<PackageReference Include="Uno.UI.RemoteControl" Version="4.1.9" Condition="'$(Configuration)'=='Debug'" />
</ItemGroup>

<ItemGroup Condition="'$(IsGtkHead)' == 'true'">
<PackageReference Include="Uno.UI.Skia.Gtk" Version="4.1.9" />
</ItemGroup>

<ItemGroup Condition="'$(IsWpfHead)' == 'true'">
<PackageReference Include="Uno.UI.Skia.Wpf" Version="4.1.9" />
</ItemGroup>

<ItemGroup Condition="'$(IsWasmHead)' == 'true'">
<PackageReference Include="Uno.UI.WebAssembly" Version="4.1.9" />
</ItemGroup>
</Project>
Loading

0 comments on commit 6ed4315

Please sign in to comment.