-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathMicrosoft.NET.Sdk.WindowsDesktop.targets
165 lines (138 loc) · 9.68 KB
/
Microsoft.NET.Sdk.WindowsDesktop.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<Project>
<PropertyGroup>
<_MicrosoftNetSdkWindowsDesktop>true</_MicrosoftNetSdkWindowsDesktop>
<EnableDefaultPageItems Condition="'$(EnableDefaultPageItems)' == ''">true</EnableDefaultPageItems>
<EnableDefaultApplicationDefinition Condition="'$(EnableDefaultApplicationDefinition)' == ''">true</EnableDefaultApplicationDefinition>
</PropertyGroup>
<PropertyGroup>
<!--
WindowsDesktop SDK supports WPF and WinForms on
- .NET Core 3.0 and greater
- .NET Framework 3.0 and greater
Note that on .NET Framework versions < 4.0, additional workarounds may be required to build applications
using the SDK style projects. For e.g., see https://github.com/microsoft/msbuild/issues/1333
Irrespective of whether '$(TargetFrameworkIdentifier)' is '.NETCoreApp' or '.NETFramework',
the minimum value of $(_TargetFrameworkVersionValue) we will be testing for is '3.0'
-->
<_WindowsDesktopSdkTargetFrameworkVersionFloor>3.0</_WindowsDesktopSdkTargetFrameworkVersionFloor>
<!--
Represents an undefined TFV value. This will be used in comparisons of _TargetFrameworkVersionValue (defined in Microsoft.NET.WindowsDesktop.targets)
to identify when a TFV is undefined
-->
<_UndefinedTargetFrameworkVersion>0.0</_UndefinedTargetFrameworkVersion>
</PropertyGroup>
<!--
$(TargetFrameworkVersion), $(_TargetFrameworkVersionWithoutV) etc. are defined in
Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets.
Microsoft.NET.Sdk.targets is included prior to this file by Sdk.targets, so it is safe to define _TargetFrameworkValue
here.
_TargetFrameworkValue will be used in WindowsDesktop SDK as reliable proxy for _TargetFrameworkVersionWithoutV.
_TargetFrameworkVersionWithoutV can be empty ('') or it can be a numeric value (e.g., '3.0') - which makes it hard to work with
esp. in outer builds. _TargetFrameworkValue will always be guaranteed to have a numeric value ('0.0' or a valid TFM).
_TargetFrameworkVersionValue will be used in Microsoft.NET.Sdk.WindowsDesktop.props in Item conditions. This will be valid
because Items are evaluated after Properties (see https://docs.microsoft.com/en-us/visualstudio/msbuild/comparing-properties-and-items?view=vs-2019).
Note:
Please see https://github.com/microsoft/msbuild/issues/3212 for a discussion about the use of
the private $(_TargetFrameworkVersionWithoutV) property - which will likely remain supported and
is safe to use here.
-->
<PropertyGroup>
<_TargetFrameworkVersionValue>$([MSBuild]::ValueOrDefault('$(_TargetFrameworkVersionWithoutV)', '$(_UndefinedTargetFrameworkVersion)'))</_TargetFrameworkVersionValue>
</PropertyGroup>
<!-- Set 7.0 as the TargetPlatformVersion for windows. -->
<PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'windows' and '$(TargetPlatformVersion)' == ''" >
<TargetPlatformVersion>7.0</TargetPlatformVersion>
</PropertyGroup>
<!-- PropertyGroup flags control if Itemgroups in Microsoft.NET.Sdk.WindowsDesktop.props file is being imported -->
<PropertyGroup>
<_EnableWindowsDesktopGlobbing Condition=" ('$(EnableDefaultItems)' == 'true') And ('$(UseWPF)' == 'true') And
('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And
('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">true</_EnableWindowsDesktopGlobbing>
<_EnableWindowsDesktopNetCoreFrameworkReferences Condition="('$(DisableImplicitFrameworkReferences)' != 'true') And
('$(TargetFrameworkIdentifier)' == '.NETCoreApp') And
('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And
('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">true</_EnableWindowsDesktopNetCoreFrameworkReferences>
<_EnableWindowsDesktopNETFrameworkImplicitReference Condition="('$(DisableImplicitFrameworkReferences)' != 'true') And
('$(TargetFrameworkIdentifier)' == '.NETFramework') And
('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And
('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">true</_EnableWindowsDesktopNETFrameworkImplicitReference>
<_EnableWindowsDesktopSupportUnsupportedTargetFramework Condition="('$(UseWPF)' == 'true' Or '$(UseWindowsForms)' == 'true') And
'$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)' And
'$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)'">true</_EnableWindowsDesktopSupportUnsupportedTargetFramework>
</PropertyGroup>
<Import Project="Microsoft.WinFX.targets" />
<ItemGroup Condition=" ('$(EnableDefaultItems)' == 'true') And ('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And
('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
<!--
In the WindowsDesktop .props, we globbed all .xaml files as Page items. If any of those files are included
as Resource, Content then remove them from the Page items.
-->
<Page Remove="@(Resource);@(Content)"
Condition="'$(EnableDefaultPageItems)' != 'false'" />
<!--
ApplicationDefinition must also be removed from Page. Otherwise, PresentationBuildTasks will include the
generated code for the ApplicationDefinition twice. We cannot do this in all cases in the props file as
ApplicationDefinition isn't available at that point in the evaluation when EnableDefaultApplicationDefinition
is false. We unconditionally remove it here as ApplicationDefinition is considered a special singleton Item
in WPF.
-->
<Page Remove="@(ApplicationDefinition)" />
<!--
The WindowsDesktop props file removes "**/*.xaml" from None if both EnableDefaultApplicationDefinition and
EnableDefaultPageItems are true. This is done so that we remove any implicitly globbed XAML files from None
in support of Visual Studio.
In the case where one or both of these properties are not true, the WindowsDesktop props file does not remove
any XAML files from None. Under those conditions, removing None from Page here will remove explicitly specified
pages causing compilation errors. We match the condition from the WindowsDesktop props file here so that we only
remove None from Page when we are guaranteed to not need those items.
-->
<Page Remove="@(None)"
Condition="'$(EnableDefaultApplicationDefinition)' != 'false' and '$(EnableDefaultPageItems)' != 'false'" />
</ItemGroup>
<!-- Generate error if there are duplicate page items. The task comes from the .NET SDK, and this target follows
the pattern in the CheckForDuplicateItems task, where the .NET SDK checks for duplicate items for the item
types it knows about. -->
<Target Name="CheckForDuplicatePageItems"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform;CoreCompile"
DependsOnTargets="CheckForDuplicateItems"
Condition="('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And ('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
<CheckForDuplicateItems
Items="@(Page)"
ItemName="Page"
DefaultItemsEnabled="$(EnableDefaultItems)"
DefaultItemsOfThisTypeEnabled="$(EnableDefaultPageItems)"
PropertyNameToDisableDefaultItems="EnableDefaultPageItems"
MoreInformationLink="$(DefaultItemsMoreInformationLink)"
ContinueOnError="$(ContinueOnError)">
<Output TaskParameter="DeduplicatedItems" ItemName="DeduplicatedPageItems" />
</CheckForDuplicateItems>
<ItemGroup Condition="'$(DesignTimeBuild)' == 'true' And '@(DeduplicatedPageItems)' != ''">
<Page Remove="@(Page)" />
<Page Include="@(DeduplicatedPageItems)" />
</ItemGroup>
</Target>
<!--
This warning can be suppressed by setting $(MSBuildWarningsAsMessages) property, like this:
<PropertyGroup>
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);NETSDK1106</MSBuildWarningsAsMessages>
</PropertyGroup>
-->
<Target Name="_WindowsDesktopFrameworkRequiresUseWpfOrUseWindowsForms"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
Condition="('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And ('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
<NetSdkWarning ResourceName="WindowsDesktopFrameworkRequiresUseWpfOrUseWindowsForms"
Condition="'$(UseWpf)' != 'true' And '$(UseWindowsForms)' != 'true'"/>
</Target>
<!--
This warning can be suppressed by setting $(MSBuildWarningsAsMessages) property, like this:
<PropertyGroup>
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);NETSDK1105</MSBuildWarningsAsMessages>
</PropertyGroup>
-->
<Target Name="_WindowsDesktopFrameworkRequiresVersion30"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
Condition="('$(TargetFrameworkIdentifier)' == '.NETCoreApp') And
('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And ('$(_TargetFrameworkVersionValue)' < '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
<NetSdkWarning ResourceName="WindowsDesktopFrameworkRequiresVersion30" />
</Target>
</Project>