Skip to content

Commit

Permalink
feat: Filter unsupported TargetFrameworks based on current OS
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban authored Mar 21, 2024
1 parent 9d43812 commit 5bfc7de
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions build/nuget/uno.winui.common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,78 @@
<TargetFrameworks></TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<!-- Restore targets -->
<UnoRemoveUnsupportedTargetFrameworks_BeforeTargets>
_LoadRestoreGraphEntryPoints
;_GetRestoreTargetFrameworksOutput
;UnoImplicitPackages
;_GetRestoreTargetFrameworksAsItems
;$(UnoRemoveUnsupportedTargetFrameworks_BeforeTargets)
</UnoRemoveUnsupportedTargetFrameworks_BeforeTargets>

<!-- Build targets -->
<UnoRemoveUnsupportedTargetFrameworks_BeforeTargets>
GetAllRuntimeIdentifiers
;_GetRestoreTargetFrameworksOutput
;_ComputeTargetFrameworkItems
;$(UnoRemoveUnsupportedTargetFrameworks_BeforeTargets)
</UnoRemoveUnsupportedTargetFrameworks_BeforeTargets>
</PropertyGroup>

<Target Name="UnoRemoveUnsupportedTargetFrameworks"
Condition=" '$(UnoDisableRemoveUnsupportedTargetFrameworks)' != 'true' "
BeforeTargets="$(UnoRemoveUnsupportedTargetFrameworks_BeforeTargets)">

<!--
This target suppresses unavailable targets for the current system.
As of 2024-03-21, iOS/Catalyst are not supported on Linux, and Windows is not supported on non-Windows systems.
-->

<ItemGroup>
<!-- Create a group that contains TFs with their identifiers -->
<_TargetFrameworksAsGroup Include="$(TargetFrameworks)" />
<_TargetFrameworksAsGroup
Update="@(_TargetFrameworksAsGroup)"
PlatformIdentifier="$([MSBuild]::GetTargetPlatformIdentifier(%(_TargetFrameworksAsGroup.Identity)))" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::IsOSPlatform('linux'))">
<!-- Filter unsupported linux targets -->
<_TargetFrameworksToRemove
Include="@(_TargetFrameworksAsGroup)"
Condition="
'%(_TargetFrameworksAsGroup.PlatformIdentifier)' == 'ios'
OR '%(_TargetFrameworksAsGroup.PlatformIdentifier)' == 'maccatalyst'
" />
</ItemGroup>

<ItemGroup Condition="!$([MSBuild]::IsOSPlatform('windows'))">
<!-- Filter windows out of unsupported targets -->
<_TargetFrameworksToRemove
Include="@(_TargetFrameworksAsGroup)"
Condition="'%(_TargetFrameworksAsGroup.PlatformIdentifier)' == 'windows'" />
</ItemGroup>

<ItemGroup>
<_TargetFrameworksAsGroup Remove="@(_TargetFrameworksToRemove)" />
</ItemGroup>

<Message
Importance="Low"
Text="The following targets frameworks are skipped because they are not supported on this system: @(_TargetFrameworksToRemove)" />

<!-- Create a global property from the filtered targets -->
<CreateProperty Value="@(_TargetFrameworksAsGroup)">
<Output
TaskParameter="Value"
PropertyName="TargetFrameworks" />
</CreateProperty>

<ItemGroup>
<_TargetFrameworksAsGroup Remove="@(_TargetFrameworksAsGroup)" />
</ItemGroup>
</Target>

</Project>

0 comments on commit 5bfc7de

Please sign in to comment.