Skip to content

Commit

Permalink
Fix 'CsWinRTIncludes' check in .targets file (#1625)
Browse files Browse the repository at this point in the history
* Fix 'CsWinRTIncludes' check in .targets file

* Remove incorrect 'PropertyGroup' items

* More tweaks
  • Loading branch information
Sergio0694 authored Jun 6, 2024
1 parent 0f49b12 commit a3dfd89
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions nuget/Microsoft.Windows.CsWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,45 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Target Name="CsWinRTSetGeneratorProperties" BeforeTargets="GenerateMSBuildEditorConfigFile;GenerateMSBuildEditorConfigFileCore">
<PropertyGroup>
<CsWinRTCcwLookupTableGeneratorEnabled Condition="'$(CsWinRTCcwLookupTableGeneratorEnabled)' == '' and
'$(CsWinRTComponent)' == 'true'">true</CsWinRTCcwLookupTableGeneratorEnabled>
<!-- If the lookup generator is enabled, the AOT source generator generates vtable entries for generic types and boxing scenarios that it detects. -->
<!-- This is not intended to be ran on projections, so we try to detect that and disable it if a projection is being generated. -->
<CsWinRTCcwLookupTableGeneratorEnabled Condition="'$(CsWinRTCcwLookupTableGeneratorEnabled)' == '' and
'$(CsWinRTComponent)' == 'true'">true</CsWinRTCcwLookupTableGeneratorEnabled>

<!--
Back-compat: first check whether 'CsWinRTIncludes' is set to a list of items.
If so, this check will set 'CsWinRTHasAnyIncludes' to 'true', and we're done.
We also check 'CsWinRTFilters' from here: setting either one is sufficient.
-->
<CsWinRTHasAnyIncludes>false</CsWinRTHasAnyIncludes>
<CsWinRTHasAnyIncludes Condition="'@(CsWinRTIncludes)' != '' or $(CsWinRTFilters.Contains('-include'))">true</CsWinRTHasAnyIncludes>

<!--
If 'CsWinRTHasAnyIncludes' is 'false', but 'CsWinRTIncludes' is not actually empty, treat it as
a 'string', and also account for people formatting it over multiple lines in the .csproj files.
That is, we trim it and remove all newline characters, and then check whether the result is not
empty. If not, then we do have some WinRT includes.
This handles eg. Win2D setting this property like so:
'''
<CSWinRTIncludes>
Microsoft.Graphics.Canvas;
</CSWinRTIncludes>
'''
-->
<CsWinRTIncludesWithFixup Condition="'$(CsWinRTHasAnyIncludes)' == 'false'">$(CSWinRTIncludes)</CsWinRTIncludesWithFixup>
<CsWinRTIncludesWithFixup Condition="'$(CsWinRTHasAnyIncludes)' == 'false'">$(CsWinRTIncludesWithFixup.Trim())</CsWinRTIncludesWithFixup>
<CsWinRTIncludesWithFixup Condition="'$(CsWinRTHasAnyIncludes)' == 'false'">$([System.Text.RegularExpressions.Regex]::Replace($(CsWinRTIncludesWithFixup), '[\r\n]', ''))</CsWinRTIncludesWithFixup>
<CsWinRTHasAnyIncludes Condition="'$(CsWinRTIncludesWithFixup)' != ''">true</CsWinRTHasAnyIncludes>

<!--
If the lookup generator is enabled, the AOT source generator generates vtable entries for generic types and boxing scenarios that it detects.
This is not intended to be ran on projections, so we try to detect that and disable it if a projection is being generated.
-->
<CsWinRTCcwLookupTableGeneratorEnabled Condition="'$(CsWinRTCcwLookupTableGeneratorEnabled)' == '' and
'$(CsWinRTGenerateProjection)' == 'true' and
'$(OutputType)' == 'Library' and
('@(CsWinRTIncludes)' != ''or $(CsWinRTFilters.Contains('-include')))">false</CsWinRTCcwLookupTableGeneratorEnabled>
<CsWinRTCcwLookupTableGeneratorEnabled Condition="'$(CsWinRTCcwLookupTableGeneratorEnabled)' == ''">true</CsWinRTCcwLookupTableGeneratorEnabled>
</PropertyGroup>
'$(CsWinRTHasAnyIncludes)' == 'true'">false</CsWinRTCcwLookupTableGeneratorEnabled>
<CsWinRTCcwLookupTableGeneratorEnabled Condition="'$(CsWinRTCcwLookupTableGeneratorEnabled)' == ''">true</CsWinRTCcwLookupTableGeneratorEnabled>
</PropertyGroup>
</Target>

<!-- Remove WinRT.Host.dll and WinRT.Host.Shim.dll references -->
Expand Down

0 comments on commit a3dfd89

Please sign in to comment.