Skip to content

Commit 9299ede

Browse files
Fixes the following:
- #685: Remove **/*.xaml from None - #327: Cannot multi-target netcoreap < 3.0 and use WindowsDesktop SDK unconditionally. - #867: Show error when neither UseWpf nor UseWindowsForms is set to true - #746: [Epic] Support WPF and WinForms specific FrameworkReferences a Profiles Also cleans up the way in which we import Microsoft.WinFX.targets - UseLegacyPresentationBuildTasks has been broken for some time now and unusable.
1 parent 2409813 commit 9299ede

File tree

2 files changed

+52
-32
lines changed

2 files changed

+52
-32
lines changed

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

+22-14
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<PropertyGroup>
33
<_MicrosoftNetSdkWindowsDesktop>true</_MicrosoftNetSdkWindowsDesktop>
44
</PropertyGroup>
5-
6-
<ItemGroup Condition=" '$(EnableDefaultItems)' == 'true' And '$(UseWPF)' == 'true'">
5+
6+
<ItemGroup Condition=" '$(EnableDefaultItems)' == 'true' And '$(UseWPF)' == 'true' And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '3.0')">
77
<ApplicationDefinition Include="App.xaml"
88
Condition="'$(EnableDefaultApplicationDefinition)' != 'false' And Exists('$(MSBuildProjectDirectory)/App.xaml') And '$(MSBuildProjectExtension)' == '.csproj'">
99
<Generator>MSBuild:Compile</Generator>
@@ -13,28 +13,36 @@
1313
<Generator>MSBuild:Compile</Generator>
1414
</ApplicationDefinition>
1515

16-
<None Remove="@(ApplicationDefinition)"
17-
Condition="'$(EnableDefaultApplicationDefinition)' != 'false'" />
18-
1916
<Page Include="**/*.xaml"
2017
Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);@(ApplicationDefinition)"
2118
Condition="'$(EnableDefaultPageItems)' != 'false'" >
2219
<Generator>MSBuild:Compile</Generator>
2320
</Page>
2421

25-
<None Remove="@(Page)"
26-
Condition="'$(EnableDefaultPageItems)' != 'false'" />
22+
23+
<!--
24+
See https://github.com/dotnet/wpf/issues/685
25+
Visual Studio would prefer that we remove **/*.xaml instead of
26+
being more precise.
27+
28+
<None Remove="@(Page)"
29+
Condition="'$(EnableDefaultPageItems)' != 'false'" />
30+
<None Remove="@(ApplicationDefinition)"
31+
Condition="'$(EnableDefaultApplicationDefinition)' != 'false'" />
32+
-->
33+
<None Remove="**/*.xaml"
34+
Condition="'$(EnableDefaultApplicationDefinition)' != 'false' And '$(EnableDefaultPageItems)' != 'false'" />
2735
</ItemGroup>
2836

29-
<ItemGroup Condition="'$(DisableImplicitFrameworkReferences)' != 'true' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(UseWPF)' == 'true' And '$(UseWindowsForms)' == 'true'">
37+
<ItemGroup Condition="('$(DisableImplicitFrameworkReferences)' != 'true') And ('$(UseWPF)' == 'true') And ('$(UseWindowsForms)' == 'true') And ('$(TargetFrameworkIdentifier)' == '.NETCoreApp') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '3.0')">
3038
<FrameworkReference Include="Microsoft.WindowsDesktop.App" IsImplicitlyDefined="true" />
3139
</ItemGroup>
3240

33-
<ItemGroup Condition="'$(DisableImplicitFrameworkReferences)' != 'true' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(UseWPF)' == 'true' And '$(UseWindowsForms)' != 'true'">
41+
<ItemGroup Condition="('$(DisableImplicitFrameworkReferences)' != 'true') And ('$(UseWPF)' == 'true') And ('$(UseWindowsForms)' != 'true') And ('$(TargetFrameworkIdentifier)' == '.NETCoreApp') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '3.0')">
3442
<FrameworkReference Include="Microsoft.WindowsDesktop.App.WPF" IsImplicitlyDefined="true" />
3543
</ItemGroup>
3644

37-
<ItemGroup Condition="'$(DisableImplicitFrameworkReferences)' != 'true' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(UseWPF)' != 'true' And '$(UseWindowsForms)' == 'true'">
45+
<ItemGroup Condition="('$(DisableImplicitFrameworkReferences)' != 'true') And ('$(UseWPF)' != 'true') And ('$(UseWindowsForms)' == 'true') And ('$(TargetFrameworkIdentifier)' == '.NETCoreApp') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '3.0')">
3846
<FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" IsImplicitlyDefined="true" />
3947
</ItemGroup>
4048

@@ -63,7 +71,7 @@
6371
the private $(_TargetFrameworkVersionWithoutV) property - which will likely remain supported and
6472
is safe to use here.
6573
-->
66-
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' And '$(_TargetFrameworkVersionWithoutV)' != ''">
74+
<ItemGroup Condition="('$(TargetFrameworkIdentifier)' == '.NETFramework') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '3.0')">
6775
<_WpfCommonNetFxReference Include="WindowsBase" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '3.0'" />
6876
<_WpfCommonNetFxReference Include="PresentationCore" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '3.0'" />
6977
<_WpfCommonNetFxReference Include="PresentationFramework" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '3.0'" />
@@ -79,15 +87,15 @@
7987
<_WpfCommonNetFxReference Include="System.Windows.Controls.Ribbon" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '4.5'" />
8088
</ItemGroup>
8189

82-
<ItemGroup Condition=" '$(DisableImplicitFrameworkReferences)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETFramework' And '$(UseWPF)' == 'true' ">
90+
<ItemGroup Condition=" ('$(DisableImplicitFrameworkReferences)' != 'true') And ('$(TargetFrameworkIdentifier)' == '.NETFramework') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '3.0') And ('$(UseWPF)' == 'true') ">
8391
<_SDKImplicitReference Include="@(_WpfCommonNetFxReference)" />
8492
</ItemGroup>
8593

86-
<ItemGroup Condition=" '$(DisableImplicitFrameworkReferences)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETFramework' And '$(UseWindowsForms)' == 'true' ">
94+
<ItemGroup Condition=" ('$(DisableImplicitFrameworkReferences)' != 'true') And ('$(TargetFrameworkIdentifier)' == '.NETFramework') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '3.0') And ('$(UseWindowsForms)' == 'true') ">
8795
<_SDKImplicitReference Include="System.Windows.Forms"/>
8896
</ItemGroup>
8997

90-
<ItemGroup Condition=" '$(DisableImplicitFrameworkReferences)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETFramework' And '$(UseWindowsForms)' == 'true' And '$(UseWPF)' == 'true' ">
98+
<ItemGroup Condition=" ('$(DisableImplicitFrameworkReferences)' != 'true') And ('$(TargetFrameworkIdentifier)' == '.NETFramework') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '3.0') And ('$(UseWindowsForms)' == 'true') And ('$(UseWPF)' == 'true') ">
9199
<_SDKImplicitReference Include="WindowsFormsIntegration"/>
92100
</ItemGroup>
93101
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
<Project>
2-
3-
<!--
4-
For now, UseLegacyPresentationBuildTasks=true can be used to use the in-box framework
5-
PresentationBuildTasks and targets when running in full framework MSBuild. This is
6-
just an escape hatch while the new PresentationBuildTasks bake.
7-
8-
When we remove this,we can remove the correpsonding corresponding mscorlib swap targets in
9-
Microsoft.DesktopUI.App.targets, and the production of ref-mscorlib shims
10-
-->
11-
<Import Project="$(MSBuildToolsPath)\Microsoft.WinFX.targets"
12-
Condition ="'$(MSBuildRuntimeType)' != 'Core' and '$(UseLegacyPresentationBuildTasks)' == 'true'"/>
13-
14-
<Import Project="Microsoft.WinFX.targets"
15-
Condition="'$(MSBuildRuntimeType)' == 'Core' or '$(UseLegacyPresentationBuildTasks)' != 'true'" />
16-
17-
<ItemGroup Condition=" '$(EnableDefaultItems)' == 'true' And '$(UseWPF)' == 'true'">
2+
<Import Project="Microsoft.WinFX.targets" />
3+
4+
<!-- $(TargetFrameworkIdentifier) can be '.NETCoreApp' or '.NETFramework' -->
5+
<ItemGroup Condition=" ('$(EnableDefaultItems)' == 'true') And ('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '3.0')">
186

197
<!-- In the WindowsDesktop .props, we globbed all .xaml files as Page items. If any of those files are included
208
as Resource, Content, or None items, then remove them from the Page items. -->
@@ -25,9 +13,10 @@
2513
<!-- Generate error if there are duplicate page items. The task comes from the .NET SDK, and this target follows
2614
the pattern in the CheckForDuplicateItems task, where the .NET SDK checks for duplicate items for the item
2715
types it knows about. -->
28-
<Target Name="CheckForDuplicatePageItems" BeforeTargets="_CheckForInvalidConfigurationAndPlatform;CoreCompile"
16+
<Target Name="CheckForDuplicatePageItems"
17+
BeforeTargets="_CheckForInvalidConfigurationAndPlatform;CoreCompile"
2918
DependsOnTargets="CheckForDuplicateItems"
30-
Condition="'$(UseWPF)' == 'true'">
19+
Condition="('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '3.0')">
3120

3221
<CheckForDuplicateItems
3322
Items="@(Page)"
@@ -47,4 +36,27 @@
4736

4837
</Target>
4938

39+
<!--
40+
This warning can be suppressed by setting $(MSBuildWarningsAsMessages) property, like this:
41+
<PropertyGroup>
42+
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);NETSDK1106</MSBuildWarningsAsMessages>
43+
</PropertyGroup>
44+
-->
45+
<Target Name="_WindowsDesktopFrameworkRequiresUseWpfOrUseWindowsForms"
46+
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
47+
Condition="'$(UseWpf)' != 'true' And '$(UseWindowsForms)' != 'true'">
48+
<NetSdkWarning ResourceName="WindowsDesktopFrameworkRequiresUseWpfOrUseWindowsForms" />
49+
</Target>
50+
51+
<!--
52+
This warning can be suppressed by setting $(MSBuildWarningsAsMessages) property, like this:
53+
<PropertyGroup>
54+
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);NETSDK1105</MSBuildWarningsAsMessages>
55+
</PropertyGroup>
56+
-->
57+
<Target Name="_WindowsDesktopFrameworkRequiresVersion30"
58+
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
59+
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(_TargetFrameworkVersionWithoutV)' != '' And '$(_TargetFrameworkVersionWithoutV)' &lt; '3.0'">
60+
<NetSdkWarning ResourceName="WindowsDesktopFrameworkRequiresVersion30" />
61+
</Target>
5062
</Project>

0 commit comments

Comments
 (0)