Added WinUI 2 / 3 switch for Uno libs and heads

This commit is contained in:
Arlo Godfrey 2022-04-12 14:58:08 -05:00
Родитель d6cd9f8377
Коммит f16088f337
6 изменённых файлов: 63 добавлений и 17 удалений

Просмотреть файл

@ -1,5 +1,6 @@
<!-- Common props for any deployable sample project head. -->
<Project>
<Import Project="$(RepositoryDirectory)common\Labs.Uno.props" />
<!-- Shared project -->
<Import Project="$(RepositoryDirectory)\common\CommunityToolkit.Labs.Shared\CommunityToolkit.Labs.Shared.projitems" Label="Shared" />

Просмотреть файл

@ -1,9 +1,8 @@
<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.
@ -19,11 +18,9 @@
$(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)'">
@ -31,10 +28,6 @@
<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" />
@ -42,15 +35,11 @@
</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" />

23
common/Labs.Uno.props Normal file
Просмотреть файл

@ -0,0 +1,23 @@
<Project>
<!--
Use "All" to prevent circular import references
We just need the TFM values.
-->
<Import Project="Labs.TargetFrameworks.All.props" />
<PropertyGroup>
<IsUno Condition="'$(TargetFramework)' != '$(UwpTargetFramework)' AND '$(TargetFramework)' != '$(WinAppSdkTargetFramework)'">True</IsUno>
<IsWasm Condition="'$(TargetFramework)' == '$(WasmHeadTargetFramework)' or '$(TargetFramework)' == '$(WasmLibTargetFramework)'">True</IsWasm>
<DefineConstants>$(DefineConstants);</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(IsUno)' == 'true'AND '$(IsWasm)' == 'false'">
<PackageReference Include="Uno.UI" Version="4.0.11" />
</ItemGroup>
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(IsWasm)' == 'true'">
<PackageReference Include="Uno.UI.WebAssembly" Version="4.0.9" />
<PackageReference Include="Uno.UI.RemoteControl" Version="4.0.9" Condition="'$(Configuration)'=='Debug'" />
</ItemGroup>
</Project>

Просмотреть файл

@ -26,8 +26,6 @@
<PackageReference Include="Microsoft.Windows.Compatibility" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Uno.Extensions.Logging.WebAssembly.Console" Version="1.0.1" />
<PackageReference Include="Uno.UI.WebAssembly" Version="4.0.9" />
<PackageReference Include="Uno.UI.RemoteControl" Version="4.0.9" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="4.0.9" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="4.0.9" />
<PackageReference Include="Uno.Wasm.Bootstrap" Version="3.1.2" />

Просмотреть файл

@ -0,0 +1,30 @@
Param (
[Parameter(HelpMessage = "The WinUI version to use when building an Uno head.", Mandatory = $true)]
[ValidateSet('2', '3')]
[string]$targets,
[Parameter(HelpMessage = "Disables suppressing changes to the Labs.Uno.props file in git, allowing changes to be committed.")]
[switch]$allowGitChanges = $false
)
if ($allowGitChanges.IsPresent) {
Write-Warning "Changes to the default Uno package reference in Labs can now be committed. Run this command again without the --allow-git-changes flag to disable committing further changes.";
git update-index --no-assume-unchanged ../Labs.Uno.props
}
else {
git update-index --assume-unchanged ../Labs.Uno.props
}
$fileContents = Get-Content -Path ../Labs.Uno.props
if ($targets -eq "3") {
$fileContents = $fileContents -replace 'Uno.UI', 'Uno.WinUI';
$fileContents = $fileContents -replace '\$\(DefineConstants\);', '$(DefineConstants);WINAPPSDK;';
}
if ($targets -eq "2") {
$fileContents = $fileContents -replace 'Uno.WinUI', 'Uno.UI';
$fileContents = $fileContents -replace '\$\(DefineConstants\);WINAPPSDK;', '$(DefineConstants);';
}
Set-Content -Force -Path ../Labs.Uno.props -Value $fileContents;

Просмотреть файл

@ -1,6 +1,11 @@
using CommunityToolkit.Labs.Shared;
using System;
#if WINAPPSDK
using Microsoft.UI.Xaml;
#else
using Windows.UI.Xaml;
#endif
namespace CommunityToolkit.Labs.Wasm
{
@ -10,7 +15,7 @@ namespace CommunityToolkit.Labs.Wasm
static int Main(string[] args)
{
Windows.UI.Xaml.Application.Start(_ => _app = new App());
Application.Start(_ => _app = new App());
return 0;
}