Skip to content

Commit 0a627fb

Browse files
Fixes problems in WindowsDesktop SDK due to _TargetFrameworkVersionWithoutV being undefined sometimes (#1707)
* Add _TargetFrameworkVersionValue * Define _UndefinedTargetFrameworkVersion * Update conditions using _TargetFrameworkVersionValue & _UndefinedTargetFrameworkVersion * Format conditions * Add a default value for _TargetFrameworkVersionValue in .props file, and fixup the default value in .targets file. Fixup an incorrect comment * Add _UndefinedTargetFrameworkVersion and _TargetFrameworkVersionValue to Pbt.targets (used for dotnet/wpf builds only)
1 parent 5fb6c49 commit 0a627fb

File tree

3 files changed

+73
-28
lines changed

3 files changed

+73
-28
lines changed

eng/WpfArcadeSdk/tools/Pbt.targets

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,20 @@
9292
Condition="'$(InternalMarkupCompilation)'=='true' And Exists('$(LocalMicrosoftWinFXTargets)') "/>
9393

9494
<!--
95-
_WindowsDesktopSdkTargetFrameworkVersionFloor is defined in Microsoft.NET.WindowDesktop.props.
96-
This needs to be defined before Microsoft.NET.Sdk.WindowsDesktop.targets is imported.
95+
_WindowsDesktopSdkTargetFrameworkVersionFloor, _UndefinedTargetFrameworkVersion and _TargetFrameworkVersionValue are
96+
defined in Microsoft.NET.WindowDesktop.props.
97+
98+
These need to be defined before Microsoft.NET.Sdk.WindowsDesktop.targets is imported.
9799
-->
98100
<PropertyGroup Condition="'$(InternalMarkupCompilation)'=='true' And !Exists('$(LocalMicrosoftWinFXTargets)') ">
99101
<_WindowsDesktopSdkTargetFrameworkVersionFloor Condition="'$(_WindowsDesktopSdkTargetFrameworkVersionFloor)' == ''">3.0</_WindowsDesktopSdkTargetFrameworkVersionFloor>
102+
103+
<!-- Represents an undefined TFV value. -->
104+
<_UndefinedTargetFrameworkVersion>0.0</_UndefinedTargetFrameworkVersion>
105+
106+
<!-- Initial/Default value set to 'undefined'. Updated in Microsoft.NET.WindowsDesktop.targets -->
107+
<_TargetFrameworkVersionValue>$(_UndefinedTargetFrameworkVersion)</_TargetFrameworkVersionValue>
108+
100109
</PropertyGroup>
101110
<Import Sdk="Microsoft.NET.Sdk.WindowsDesktop"
102111
Project="../targets/Microsoft.NET.Sdk.WindowsDesktop.targets"

packaging/Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.props

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@
1515
using the SDK style projects. For e.g., see https://github.com/microsoft/msbuild/issues/1333
1616
1717
Irrespective of whether '$(TargetFrameworkIdentifier)' is '.NETCoreApp' or '.NETFramework',
18-
the minimum value of $(_TargetFrameworkVersionWithoutV) we will be testing for is '3.0'
18+
the minimum value of $(_TargetFrameworkVersionValue) we will be testing for is '3.0'
1919
20-
Note:
21-
Please see https://github.com/microsoft/msbuild/issues/3212 for a discussion about the use of
22-
the private $(_TargetFrameworkVersionWithoutV) property - which will likely remain supported and
23-
is safe to use here.
2420
-->
2521
<_WindowsDesktopSdkTargetFrameworkVersionFloor>3.0</_WindowsDesktopSdkTargetFrameworkVersionFloor>
22+
23+
<!--
24+
Represents an undefined TFV value. This will be used in comparisons of _TargetFrameworkVersionValue (defined in Microsoft.NET.WindowsDesktop.targets)
25+
to identify when a TFV is undefined
26+
-->
27+
<_UndefinedTargetFrameworkVersion>0.0</_UndefinedTargetFrameworkVersion>
28+
29+
<!--
30+
Initial/Default value set to 'undefined'. Updated in Microsoft.NET.WindowsDesktop.targets
31+
-->
32+
<_TargetFrameworkVersionValue>$(_UndefinedTargetFrameworkVersion)</_TargetFrameworkVersionValue>
2633
</PropertyGroup>
2734

2835
<ItemGroup Condition=" ('$(EnableDefaultItems)' == 'true') And ('$(UseWPF)' == 'true') And
29-
('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
36+
('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And
37+
('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
3038
<ApplicationDefinition Include="App.xaml"
3139
Condition="'$(EnableDefaultApplicationDefinition)' != 'false' And Exists('$(MSBuildProjectDirectory)/App.xaml') And '$(MSBuildProjectExtension)' == '.csproj'">
3240
<Generator>MSBuild:Compile</Generator>
@@ -60,8 +68,8 @@
6068

6169
<ItemGroup Condition="('$(DisableImplicitFrameworkReferences)' != 'true') And
6270
('$(TargetFrameworkIdentifier)' == '.NETCoreApp') And
63-
('$(_TargetFrameworkVersionWithoutV)' != '') And
64-
('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
71+
('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And
72+
('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
6573

6674
<FrameworkReference Include="Microsoft.WindowsDesktop.App" IsImplicitlyDefined="true"
6775
Condition="('$(UseWPF)' == 'true') And ('$(UseWindowsForms)' == 'true')"/>
@@ -95,33 +103,36 @@
95103
System.Windows.Controls.Ribbon
96104
97105
-->
98-
<ItemGroup Condition="('$(TargetFrameworkIdentifier)' == '.NETFramework') And ('$(_TargetFrameworkVersionWithoutV)' != '') And
99-
('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
106+
<ItemGroup Condition="('$(TargetFrameworkIdentifier)' == '.NETFramework') And
107+
('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And
108+
('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
100109

101110
<!--
102-
The following 3 _WpfCommonNetFxReference items normally require Condition="'$(_TargetFrameworkVersionWithoutV)' >= '3.0'", since
111+
The following 3 _WpfCommonNetFxReference items normally require Condition="'$(_TargetFrameworkVersionValue)' >= '3.0'", since
103112
they are supported on .NET Framework 3.0 and above.
104113
105-
This condition is implicitly satisfied by '$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)'
114+
This condition is implicitly satisfied by '$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)'
106115
in the outer ItemGroup
107116
-->
108117
<_WpfCommonNetFxReference Include="WindowsBase" />
109118
<_WpfCommonNetFxReference Include="PresentationCore" />
110119
<_WpfCommonNetFxReference Include="PresentationFramework" />
111120

112-
<_WpfCommonNetFxReference Include="System.Xaml" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '4.0'">
121+
<_WpfCommonNetFxReference Include="System.Xaml" Condition="'$(_TargetFrameworkVersionValue)' >= '4.0'">
113122
<RequiredTargetFramework>4.0</RequiredTargetFramework>
114123
</_WpfCommonNetFxReference>
115-
<_WpfCommonNetFxReference Include="UIAutomationClient" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '4.0'" />
116-
<_WpfCommonNetFxReference Include="UIAutomationClientSideProviders" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '4.0'" />
117-
<_WpfCommonNetFxReference Include="UIAutomationProvider" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '4.0'" />
118-
<_WpfCommonNetFxReference Include="UIAutomationTypes" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '4.0'" />
124+
<_WpfCommonNetFxReference Include="UIAutomationClient" Condition="'$(_TargetFrameworkVersionValue)' >= '4.0'" />
125+
<_WpfCommonNetFxReference Include="UIAutomationClientSideProviders" Condition="'$(_TargetFrameworkVersionValue)' >= '4.0'" />
126+
<_WpfCommonNetFxReference Include="UIAutomationProvider" Condition="'$(_TargetFrameworkVersionValue)' >= '4.0'" />
127+
<_WpfCommonNetFxReference Include="UIAutomationTypes" Condition="'$(_TargetFrameworkVersionValue)' >= '4.0'" />
119128

120-
<_WpfCommonNetFxReference Include="System.Windows.Controls.Ribbon" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '4.5'" />
129+
<_WpfCommonNetFxReference Include="System.Windows.Controls.Ribbon" Condition="'$(_TargetFrameworkVersionValue)' >= '4.5'" />
121130
</ItemGroup>
122131

123-
<ItemGroup Condition="('$(DisableImplicitFrameworkReferences)' != 'true') And ('$(TargetFrameworkIdentifier)' == '.NETFramework') And
124-
('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
132+
<ItemGroup Condition="('$(DisableImplicitFrameworkReferences)' != 'true') And
133+
('$(TargetFrameworkIdentifier)' == '.NETFramework') And
134+
('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And
135+
('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
125136

126137
<_SDKImplicitReference Include="@(_WpfCommonNetFxReference)"
127138
Condition="'$(UseWPF)' == 'true'"/>
@@ -153,7 +164,8 @@
153164
Detect these situations and skip updates to @(SupportedTargetFramework) etc.
154165
-->
155166
<ItemGroup Condition="('$(UseWPF)' == 'true' Or '$(UseWindowsForms)' == 'true') And
156-
'$(_TargetFrameworkVersionWithoutV)' != '' And '$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)'">
167+
'$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)' And
168+
'$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)'">
157169

158170
<!--
159171
Windows Forms and WPF are supported only on .NET Core 3.0+

packaging/Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
<Project>
2+
3+
<!--
4+
$(TargetFrameworkVersion), $(_TargetFrameworkVersionWithoutV) etc. are defined in
5+
Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets.
6+
7+
Microsoft.NET.Sdk.targets is included prior to this file by Sdk.targets, so it is safe to define _TargetFrameworkValue
8+
here.
9+
10+
_TargetFrameworkValue will be used in WindowsDesktop SDK as reliable proxy for _TargetFrameworkVersionWithoutV.
11+
_TargetFrameworkVersionWithoutV can be empty ('') or it can be a numeric value (e.g., '3.0') - which makes it hard to work with
12+
esp. in outer builds. _TargetFrameworkValue will always be guaranteed to have a numeric value ('0.0' or a valid TFM).
13+
14+
_TargetFrameworkVersionValue will be used in Microsoft.NET.Sdk.WindowsDesktop.props in Item conditions. This will be valid
15+
because Items are evaluated after Properties (see https://docs.microsoft.com/en-us/visualstudio/msbuild/comparing-properties-and-items?view=vs-2019).
16+
17+
Note:
18+
Please see https://github.com/microsoft/msbuild/issues/3212 for a discussion about the use of
19+
the private $(_TargetFrameworkVersionWithoutV) property - which will likely remain supported and
20+
is safe to use here.
21+
-->
22+
<PropertyGroup>
23+
<_TargetFrameworkVersionValue>$([MSBuild]::ValueOrDefault('$(_TargetFrameworkVersionWithoutV)', '$(_UndefinedTargetFrameworkVersion)'))</_TargetFrameworkVersionValue>
24+
</PropertyGroup>
25+
226
<Import Project="Microsoft.WinFX.targets" />
327

4-
<ItemGroup Condition=" ('$(EnableDefaultItems)' == 'true') And ('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionWithoutV)' != '') And
5-
('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
28+
<ItemGroup Condition=" ('$(EnableDefaultItems)' == 'true') And ('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And
29+
('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
630

731
<!-- In the WindowsDesktop .props, we globbed all .xaml files as Page items. If any of those files are included
832
as Resource, Content, or None items, then remove them from the Page items. -->
@@ -16,7 +40,7 @@
1640
<Target Name="CheckForDuplicatePageItems"
1741
BeforeTargets="_CheckForInvalidConfigurationAndPlatform;CoreCompile"
1842
DependsOnTargets="CheckForDuplicateItems"
19-
Condition="('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
43+
Condition="('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And ('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
2044

2145
<CheckForDuplicateItems
2246
Items="@(Page)"
@@ -44,7 +68,7 @@
4468
-->
4569
<Target Name="_WindowsDesktopFrameworkRequiresUseWpfOrUseWindowsForms"
4670
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
47-
Condition="('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
71+
Condition="('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And ('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
4872
<NetSdkWarning ResourceName="WindowsDesktopFrameworkRequiresUseWpfOrUseWindowsForms"
4973
Condition="'$(UseWpf)' != 'true' And '$(UseWindowsForms)' != 'true'"/>
5074
</Target>
@@ -58,7 +82,7 @@
5882
<Target Name="_WindowsDesktopFrameworkRequiresVersion30"
5983
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
6084
Condition="('$(TargetFrameworkIdentifier)' == '.NETCoreApp') And
61-
('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' &lt; '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
85+
('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And ('$(_TargetFrameworkVersionValue)' &lt; '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
6286
<NetSdkWarning ResourceName="WindowsDesktopFrameworkRequiresVersion30" />
6387
</Target>
6488
</Project>

0 commit comments

Comments
 (0)