Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiTarget updates: Organize GlobalUsings, add HasWinUI2 msbuild property #234

Merged
merged 7 commits into from
Dec 21, 2024
Merged
4 changes: 0 additions & 4 deletions .github/workflows/config/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,4 @@
<IsPublishable>true</IsPublishable>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(RepositoryDirectory)tooling\GlobalUsings.cs" />
</ItemGroup>
</Project>
40 changes: 40 additions & 0 deletions MultiTarget/Extra.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project>
<PropertyGroup Condition="'$(IsWinAppSdk)' == 'true' OR '$(IsUwp)' == 'true'">
<!--
For net5.0+ targets, TargetPlatformMinVersion was renamed to SupportedOSPlatformVersion. See https://github.com/dotnet/designs/pull/157

The dotnet SDK uses the TargetPlatformVersion property to provide a default SupportedOSPlatformVersion value if none is explicitly provided.
See https://github.com/dotnet/designs/blob/bba3216250cb29b0063bac3ebb57a542ee21ad4f/accepted/2020/minimum-os-version/minimum-os-version.md?plain=1#L73C27-L73C48
-->
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion>$(TargetPlatformMinVersion)</SupportedOSPlatformVersion>
<TargetPlatformVersion Condition="'$(MultiTargetPlatformIdentifier)' == 'windows'">10.0.26100.0</TargetPlatformVersion>
<TargetPlatformVersion Condition="'$(MultiTargetPlatformIdentifier)' != 'windows'">10.0.19041.0</TargetPlatformVersion>
</PropertyGroup>

<!-- Workaround, improved error message when consuming from Uno projects with mismatched TFMs -->
<!-- See https://github.com/CommunityToolkit/Windows/issues/388 -->
<ItemGroup>
<None PackagePath="lib/net9.0-windows10.0.18362" Include="$(MSBuildThisFileDirectory)/_._" Pack="true" />
<None PackagePath="lib/net8.0-windows10.0.18362" Include="$(MSBuildThisFileDirectory)/_._" Pack="true" />
<None PackagePath="lib/net7.0-windows10.0.18362" Include="$(MSBuildThisFileDirectory)/_._" Pack="true" />
</ItemGroup>

<PropertyGroup Condition="'$(IsUwp)' == 'true'">
<Platforms>x86;x64;arm64</Platforms>

<WindowsSdkPackageVersion Condition="'$(MultiTargetPlatformIdentifier)' == 'windows'">10.0.26100.54</WindowsSdkPackageVersion>
<RuntimeIdentifiers Condition="'$(MultiTargetPlatformIdentifier)' == 'windows'">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
</PropertyGroup>

<PropertyGroup Condition="'$(IsWinAppSdk)' == 'true'">
<!-- See https://github.com/microsoft/WindowsAppSDK/issues/3842 -->
<UseRidGraph>true</UseRidGraph>

<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition="8 > $([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)'))">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>

<!--- Workaround for ADO 53865998 - See https://github.com/CommunityToolkit/Tooling-Windows-Submodule/issues/215 - Don't include extraneous WebView2 dll -->
<WebView2NeverCopyLoaderDllToOutputDirectory>true</WebView2NeverCopyLoaderDllToOutputDirectory>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions MultiTarget/GlobalUsings.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<ItemGroup>
<Compile Condition="'$(EnableGlobalUsings)' != 'false' AND '$(HasWinUI)' == 'true'" Include="$(ToolingDirectory)\GlobalUsings_WinUI.cs" />
<Compile Condition="'$(EnableGlobalUsings)' != 'false'" Include="$(ToolingDirectory)\GlobalUsings.cs" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions MultiTarget/Library.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
<Import Project="$(ToolingDirectory)\MultiTarget\MultiTargetIdentifiers.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\DefinedConstants.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\NoWarn.props"/>
<Import Project="$(ToolingDirectory)\MultiTarget\GlobalUsings.props" />

<!-- Add platform package dependencies -->
<Import Project="$(ToolingDirectory)\MultiTarget\PackageReferences\Uno.props" Condition="$(IsUno) == 'true'" />
<Import Project="$(ToolingDirectory)\MultiTarget\PackageReferences\Uwp.props" Condition="$(IsUwp) == 'true'"/>
<Import Project="$(ToolingDirectory)\MultiTarget\PackageReferences\WinAppSdk.props" Condition="$(IsWinAppSdk) == 'true'"/>
<Import Project="$(ToolingDirectory)\MultiTarget\Extra.props" />

<!-- Configure WinUI -->
<Import Project="$(ToolingDirectory)\MultiTarget\WinUI.AutoIncludeXamlPages.props" Condition="$(HasWinUI) == 'true'" />
Expand Down
8 changes: 5 additions & 3 deletions MultiTarget/MultiTargetIdentifiers.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@

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

<HasWinUI Condition="'$(HasWinUI)' == '' AND ('$(IsUwp)' == 'true' OR '$(IsWinAppSdk)' == 'true' OR '$(IsUno)' == 'true')">true</HasWinUI>

<!--
This property is only for changing the version used by Uno.
Force the version to 2 for UWP and 3 for WinAppSDK.
-->
<WinUIMajorVersion Condition="'$(HasWinUI)' == 'true' AND '$(IsUwp)' == 'true' AND $(WinUIMajorVersion) == ''">2</WinUIMajorVersion>
<WinUIMajorVersion Condition="'$(HasWinUI)' == 'true' AND '$(IsWinAppSdk)' == 'true' AND $(WinUIMajorVersion) == ''">3</WinUIMajorVersion>
<WinUIMajorVersion Condition="'$(IsUwp)' == 'true'">2</WinUIMajorVersion>
<WinUIMajorVersion Condition="'$(IsWinAppSdk)' == 'true'">3</WinUIMajorVersion>

<HasWinUI Condition="'$(HasWinUI)' == '' AND '$(WinUIMajorVersion)' == '2' AND '$(HasWinUI2)' == 'false'">false</HasWinUI>
<HasWinUI Condition="'$(HasWinUI)' == '' AND ('$(IsUwp)' == 'true' OR '$(IsWinAppSdk)' == 'true' OR '$(IsUno)' == 'true')">true</HasWinUI>

<UseUwp Condition="'$(HasWinUI)' == 'true' AND '$(IsUwp)' == 'true' AND '$(MultiTargetPlatformIdentifier)' == 'windows'">true</UseUwp>
</PropertyGroup>
Expand Down
58 changes: 0 additions & 58 deletions MultiTarget/WinUI.Extra.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,6 @@
<EnableDefaultPageItems>false</EnableDefaultPageItems>
</PropertyGroup>

<PropertyGroup Condition="'$(IsWinAppSdk)' == 'true' OR '$(IsUwp)' == 'true'">
<!--
For net5.0+ targets, TargetPlatformMinVersion was renamed to SupportedOSPlatformVersion. See https://github.com/dotnet/designs/pull/157

The dotnet SDK uses the TargetPlatformVersion property to provide a default SupportedOSPlatformVersion value if none is explicitly provided.
See https://github.com/dotnet/designs/blob/bba3216250cb29b0063bac3ebb57a542ee21ad4f/accepted/2020/minimum-os-version/minimum-os-version.md?plain=1#L73C27-L73C48
-->
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion>$(TargetPlatformMinVersion)</SupportedOSPlatformVersion>
<TargetPlatformVersion Condition="'$(MultiTargetPlatformIdentifier)' == 'windows'">10.0.26100.0</TargetPlatformVersion>
<TargetPlatformVersion Condition="'$(MultiTargetPlatformIdentifier)' != 'windows'">10.0.19041.0</TargetPlatformVersion>
</PropertyGroup>

<!-- Workaround, improved error message when consuming from Uno projects with mismatched TFMs -->
<!-- See https://github.com/CommunityToolkit/Windows/issues/388 -->
<ItemGroup>
<None PackagePath="lib/net9.0-windows10.0.18362" Include="$(MSBuildThisFileDirectory)/_._" Pack="true" />
<None PackagePath="lib/net8.0-windows10.0.18362" Include="$(MSBuildThisFileDirectory)/_._" Pack="true" />
<None PackagePath="lib/net7.0-windows10.0.18362" Include="$(MSBuildThisFileDirectory)/_._" Pack="true" />
</ItemGroup>

<PropertyGroup Condition="'$(IsUwp)' == 'true'">
<Platforms>x86;x64;arm64</Platforms>

<WindowsSdkPackageVersion Condition="'$(MultiTargetPlatformIdentifier)' == 'windows'">10.0.26100.54</WindowsSdkPackageVersion>
<RuntimeIdentifiers Condition="'$(MultiTargetPlatformIdentifier)' == 'windows'">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
</PropertyGroup>

<PropertyGroup Condition="'$(IsWinAppSdk)' == 'true'">
<!-- See https://github.com/microsoft/WindowsAppSDK/issues/3842 -->
<UseRidGraph>true</UseRidGraph>

<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition="8 > $([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)'))">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>

<!--- Workaround for ADO 53865998 - See https://github.com/CommunityToolkit/Tooling-Windows-Submodule/issues/215 - Don't include extraneous WebView2 dll -->
<WebView2NeverCopyLoaderDllToOutputDirectory>true</WebView2NeverCopyLoaderDllToOutputDirectory>
</PropertyGroup>

<PropertyGroup Condition="'$(IsUno)' == 'true'">
<!-- Xaml Trimming: https://platform.uno/docs/articles/features/resources-trimming.html -->
<UnoXamlResourcesTrimming>true</UnoXamlResourcesTrimming>
Expand All @@ -56,23 +17,4 @@
<!-- These suppressions are for references between generated assemblies and that VS can keep in the Error List once resolved -->
<NoWarn>$(NoWarn);WMC1006;CS8034;</NoWarn>
</PropertyGroup>

<!-- Disable warnings for 'This call site is reachable on all platforms.' caused by underlying platform. -->
<PropertyGroup Condition="'$(IsUwp)' == 'true' AND '$(MultiTargetPlatformIdentifier)' == 'windows'">
<NoWarn>$(NoWarn);CA1416;</NoWarn>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(ToolingDirectory)\GlobalUsings_WinUI.cs" />
</ItemGroup>

<!-- Workaround for Mac: https://developercommunity.visualstudio.com/t/XamarinMac-binaries-are-missing-in-173/10164443#T-N10164676 10/6/22 -->
<ItemGroup Condition=" $(TargetFramework.StartsWith('xamarinmac')) ">
<Reference Include="Xamarin.Mac">
<HintPath Condition="Exists('c:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Xamarin.VisualStudio')">c:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Xamarin.VisualStudio\Xamarin.Mac.dll</HintPath>
<HintPath Condition="Exists('c:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\Xamarin.VisualStudio')">c:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\Xamarin.VisualStudio\Xamarin.Mac.dll</HintPath>
<HintPath Condition="Exists('c:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Xamarin.VisualStudio')">c:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Xamarin.VisualStudio\Xamarin.Mac.dll</HintPath>
<HintPath Condition="Exists('c:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\Extensions\Xamarin.VisualStudio')">c:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\Extensions\Xamarin.VisualStudio\Xamarin.Mac.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions ProjectHeads/App.Head.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!-- Common props for any deployable app project head. -->
<Project>
<Import Project="$(MSBuildThisFileDirectory)\..\MultiTarget\Extra.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\GlobalUsings.props" />

<!-- Shared project -->
<Import Project="$(ToolingDirectory)\CommunityToolkit.App.Shared\CommunityToolkit.App.Shared.projitems" Label="Shared" />

Expand Down
1 change: 0 additions & 1 deletion ProjectHeads/GenerateSingleSampleHeads.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ if ($MultiTargets.Contains('uwp') -and $MultiTargets.Contains('wasdk'))
}

$MultiTargets = $MultiTargets | Where-Object { $_ -notin $ExcludeMultiTargets }
$ExcludeMultiTargets = $ExcludeMultiTargets | Where-Object { $_ -notin $MultiTargets }

# Generate required props for preferences
& $PSScriptRoot/../MultiTarget/UseTargetFrameworks.ps1 -MultiTargets $MultiTargets
Expand Down
3 changes: 3 additions & 0 deletions ProjectHeads/Tests.Head.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)\..\MultiTarget\Extra.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\GlobalUsings.props" />

<!-- Source generators -->
<ItemGroup Condition="'$(IsWinAppSdk)' != 'true'">
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" PrivateAssets="all" />
Expand Down
Loading