Skip to content

Add warnings to Microsoft.NET.Sdk.WindowsDesktop to improve UseWpf/UseWinforms and multi-targeting experience #1027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tools": {
"dotnet": "3.0.100-preview6-012264",
"dotnet": "3.0.100-preview7-012512",
"runtimes": {
"dotnet": [
"2.1.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,29 @@
<PropertyGroup>
<_MicrosoftNetSdkWindowsDesktop>true</_MicrosoftNetSdkWindowsDesktop>
</PropertyGroup>

<ItemGroup Condition=" '$(EnableDefaultItems)' == 'true' And '$(UseWPF)' == 'true'">

<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 $(_TargetFrameworkVersionWithoutV) we will be testing for is '3.0'

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.
-->
<_WindowsDesktopSdkTargetFrameworkVersionFloor>3.0</_WindowsDesktopSdkTargetFrameworkVersionFloor>
</PropertyGroup>

<ItemGroup Condition=" ('$(EnableDefaultItems)' == 'true') And ('$(UseWPF)' == 'true') And
('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
<ApplicationDefinition Include="App.xaml"
Condition="'$(EnableDefaultApplicationDefinition)' != 'false' And Exists('$(MSBuildProjectDirectory)/App.xaml') And '$(MSBuildProjectExtension)' == '.csproj'">
<Generator>MSBuild:Compile</Generator>
Expand All @@ -13,30 +34,43 @@
<Generator>MSBuild:Compile</Generator>
</ApplicationDefinition>

<None Remove="@(ApplicationDefinition)"
Condition="'$(EnableDefaultApplicationDefinition)' != 'false'" />

<Page Include="**/*.xaml"
Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);@(ApplicationDefinition)"
Condition="'$(EnableDefaultPageItems)' != 'false'" >
<Generator>MSBuild:Compile</Generator>
</Page>

<None Remove="@(Page)"
Condition="'$(EnableDefaultPageItems)' != 'false'" />
</ItemGroup>

<ItemGroup Condition="'$(DisableImplicitFrameworkReferences)' != 'true' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(UseWPF)' == 'true' And '$(UseWindowsForms)' == 'true'">
<FrameworkReference Include="Microsoft.WindowsDesktop.App" IsImplicitlyDefined="true" />
</ItemGroup>
<!--
See https://github.com/dotnet/wpf/issues/685
Visual Studio would prefer that we remove **/*.xaml instead of
being more precise.

<ItemGroup Condition="'$(DisableImplicitFrameworkReferences)' != 'true' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(UseWPF)' == 'true' And '$(UseWindowsForms)' != 'true'">
<FrameworkReference Include="Microsoft.WindowsDesktop.App.WPF" IsImplicitlyDefined="true" />
<None Remove="@(Page)"
Condition="'$(EnableDefaultPageItems)' != 'false'" />
<None Remove="@(ApplicationDefinition)"
Condition="'$(EnableDefaultApplicationDefinition)' != 'false'" />
-->
<None Remove="**/*.xaml"
Condition="'$(EnableDefaultApplicationDefinition)' != 'false' And '$(EnableDefaultPageItems)' != 'false'" />
</ItemGroup>

<ItemGroup Condition="'$(DisableImplicitFrameworkReferences)' != 'true' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(UseWPF)' != 'true' And '$(UseWindowsForms)' == 'true'">
<FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" IsImplicitlyDefined="true" />

<ItemGroup Condition="('$(DisableImplicitFrameworkReferences)' != 'true') And
('$(TargetFrameworkIdentifier)' == '.NETCoreApp') And
('$(_TargetFrameworkVersionWithoutV)' != '') And
('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">

<FrameworkReference Include="Microsoft.WindowsDesktop.App" IsImplicitlyDefined="true"
Condition="('$(UseWPF)' == 'true') And ('$(UseWindowsForms)' == 'true')"/>

<FrameworkReference Include="Microsoft.WindowsDesktop.App.WPF" IsImplicitlyDefined="true"
Condition="('$(UseWPF)' == 'true') And ('$(UseWindowsForms)' != 'true')"/>

<FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" IsImplicitlyDefined="true"
Condition="('$(UseWPF)' != 'true') And ('$(UseWindowsForms)' == 'true')"/>
</ItemGroup>


<!--
Traditionally, Visual Studio has supplied these references for .NET Framework based
Expand All @@ -57,16 +91,21 @@
.NET 4.5+: PresentationCore, PresentationFramework, WindowsBase, System.Xaml,
UIAutomationClient, UIAutomationClientSideProviders, UIAutomationProvider, UIAutomationTypes
System.Windows.Controls.Ribbon

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.

-->
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' And '$(_TargetFrameworkVersionWithoutV)' != ''">
<_WpfCommonNetFxReference Include="WindowsBase" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '3.0'" />
<_WpfCommonNetFxReference Include="PresentationCore" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '3.0'" />
<_WpfCommonNetFxReference Include="PresentationFramework" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '3.0'" />
<ItemGroup Condition="('$(TargetFrameworkIdentifier)' == '.NETFramework') And ('$(_TargetFrameworkVersionWithoutV)' != '') And
('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">

<!--
The following 3 _WpfCommonNetFxReference items normally require Condition="'$(_TargetFrameworkVersionWithoutV)' >= '3.0'", since
they are supported on .NET Framework 3.0 and above.

This condition is implicitly satisfied by '$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)'
in the outer ItemGroup
-->
<_WpfCommonNetFxReference Include="WindowsBase" />
<_WpfCommonNetFxReference Include="PresentationCore" />
<_WpfCommonNetFxReference Include="PresentationFramework" />

<_WpfCommonNetFxReference Include="System.Xaml" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '4.0'">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
Expand All @@ -79,15 +118,16 @@
<_WpfCommonNetFxReference Include="System.Windows.Controls.Ribbon" Condition="'$(_TargetFrameworkVersionWithoutV)' >= '4.5'" />
</ItemGroup>

<ItemGroup Condition=" '$(DisableImplicitFrameworkReferences)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETFramework' And '$(UseWPF)' == 'true' ">
<_SDKImplicitReference Include="@(_WpfCommonNetFxReference)" />
</ItemGroup>

<ItemGroup Condition=" '$(DisableImplicitFrameworkReferences)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETFramework' And '$(UseWindowsForms)' == 'true' ">
<_SDKImplicitReference Include="System.Windows.Forms"/>
</ItemGroup>

<ItemGroup Condition=" '$(DisableImplicitFrameworkReferences)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETFramework' And '$(UseWindowsForms)' == 'true' And '$(UseWPF)' == 'true' ">
<_SDKImplicitReference Include="WindowsFormsIntegration"/>
<ItemGroup Condition="('$(DisableImplicitFrameworkReferences)' != 'true') And ('$(TargetFrameworkIdentifier)' == '.NETFramework') And
('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">

<_SDKImplicitReference Include="@(_WpfCommonNetFxReference)"
Condition="'$(UseWPF)' == 'true'"/>

<_SDKImplicitReference Include="System.Windows.Forms"
Condition="('$(UseWindowsForms)' == 'true') " />

<_SDKImplicitReference Include="WindowsFormsIntegration"
Condition=" ('$(UseWindowsForms)' == 'true') And ('$(UseWPF)' == 'true') "/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
<Project>
<Import Project="Microsoft.WinFX.targets" />

<!--
For now, UseLegacyPresentationBuildTasks=true can be used to use the in-box framework
PresentationBuildTasks and targets when running in full framework MSBuild. This is
just an escape hatch while the new PresentationBuildTasks bake.

When we remove this,we can remove the correpsonding corresponding mscorlib swap targets in
Microsoft.DesktopUI.App.targets, and the production of ref-mscorlib shims
-->
<Import Project="$(MSBuildToolsPath)\Microsoft.WinFX.targets"
Condition ="'$(MSBuildRuntimeType)' != 'Core' and '$(UseLegacyPresentationBuildTasks)' == 'true'"/>

<Import Project="Microsoft.WinFX.targets"
Condition="'$(MSBuildRuntimeType)' == 'Core' or '$(UseLegacyPresentationBuildTasks)' != 'true'" />

<ItemGroup Condition=" '$(EnableDefaultItems)' == 'true' And '$(UseWPF)' == 'true'">
<ItemGroup Condition=" ('$(EnableDefaultItems)' == 'true') And ('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionWithoutV)' != '') And
('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">

<!-- In the WindowsDesktop .props, we globbed all .xaml files as Page items. If any of those files are included
as Resource, Content, or None items, then remove them from the Page items. -->
Expand All @@ -25,9 +13,10 @@
<!-- 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"
<Target Name="CheckForDuplicatePageItems"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform;CoreCompile"
DependsOnTargets="CheckForDuplicateItems"
Condition="'$(UseWPF)' == 'true'">
Condition="('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">

<CheckForDuplicateItems
Items="@(Page)"
Expand All @@ -47,4 +36,29 @@

</Target>

<!--
This warning can be suppressed by setting $(MSBuildWarningsAsMessages) property, like this:
<PropertyGroup>
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);NETSDK1106</MSBuildWarningsAsMessages>
</PropertyGroup>
-->
<Target Name="_WindowsDesktopFrameworkRequiresUseWpfOrUseWindowsForms"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
Condition="('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '$(_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
('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' &lt; '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
<NetSdkWarning ResourceName="WindowsDesktopFrameworkRequiresVersion30" />
</Target>
</Project>