Skip to content
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

Don't double import WinFX targets #2976

Merged
merged 4 commits into from
Jan 12, 2021
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 packaging/Microsoft.NET.Sdk.WindowsDesktop/Sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.

Copyright (c) .NET Foundation. All rights reserved.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project>
Expand Down
3 changes: 2 additions & 1 deletion packaging/Microsoft.NET.Sdk.WindowsDesktop/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.

Copyright (c) .NET Foundation. All rights reserved.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project>

<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />

<!--Post 5.0, Microsoft.NET.Sdk.WindowsDesktop.targets will be imported by SDK conditionally-->

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project>

<ItemGroup Condition=" '$(_EnableWindowsDesktopGlobbing)' == 'true' ">
<ApplicationDefinition Include="App.xaml"
Condition="'$(EnableDefaultApplicationDefinition)' != 'false' And Exists('$(MSBuildProjectDirectory)/App.xaml') And '$(MSBuildProjectExtension)' == '.csproj'">
Expand All @@ -19,9 +20,9 @@
</Page>


<!--
<!--
See https://github.com/dotnet/wpf/issues/685
Visual Studio would prefer that we remove **/*.xaml instead of
Visual Studio would prefer that we remove **/*.xaml instead of
being more precise.

<None Remove="@(Page)"
Expand All @@ -33,7 +34,7 @@
Condition="'$(EnableDefaultApplicationDefinition)' != 'false' And '$(EnableDefaultPageItems)' != 'false'" />
</ItemGroup>


<ItemGroup Condition=" '$(_EnableWindowsDesktopNetCoreFrameworkReferences)' == 'true' ">

<FrameworkReference Include="Microsoft.WindowsDesktop.App" IsImplicitlyDefined="true"
Expand All @@ -45,39 +46,37 @@
<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
WPF Projects:
.NET 3.x: PresentationCore, PresentationFramework, WindowsBase
.NET 4.x: PresentationCore, PresentationFramework, WindowsBase, System.Xaml


Microsoft.NET.WindowsDesktop.SDK will supply the following references to .NET Framework based
WPF Projects:
.NET 3.x: PresentationCore, PresentationFramework, WindowsBase
.NET 4.0: PresentationCore, PresentationFramework, WindowsBase, System.Xaml,
WPF Projects:

.NET 3.x: PresentationCore, PresentationFramework, WindowsBase
.NET 4.x: PresentationCore, PresentationFramework, WindowsBase, System.Xaml


Microsoft.NET.WindowsDesktop.SDK will supply the following references to .NET Framework based
WPF Projects:

.NET 3.x: PresentationCore, PresentationFramework, WindowsBase

.NET 4.0: PresentationCore, PresentationFramework, WindowsBase, System.Xaml,
UIAutomationClient, UIAutomationClientSideProviders, UIAutomationProvider, UIAutomationTypes
.NET 4.5+: PresentationCore, PresentationFramework, WindowsBase, System.Xaml,

.NET 4.5+: PresentationCore, PresentationFramework, WindowsBase, System.Xaml,
UIAutomationClient, UIAutomationClientSideProviders, UIAutomationProvider, UIAutomationTypes
System.Windows.Controls.Ribbon

-->
<ItemGroup Condition=" '$(_EnableWindowsDesktopNETFrameworkImplicitReference)' == 'true' ">

<!--
The following 3 _WpfCommonNetFxReference items normally require Condition="'$(_TargetFrameworkVersionValue)' >= '3.0'", since
they are supported on .NET Framework 3.0 and above.
This condition is implicitly satisfied by '$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)'
they are supported on .NET Framework 3.0 and above.

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

Expand All @@ -93,39 +92,38 @@
</ItemGroup>

<ItemGroup Condition=" '$(_EnableWindowsDesktopNETFrameworkImplicitReference)' == 'true' ">

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

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

<_SDKImplicitReference Include="WindowsFormsIntegration"
Condition=" ('$(UseWindowsForms)' == 'true') And ('$(UseWPF)' == 'true') "/>
</ItemGroup>
<!--
Supported (and unsupported) TargetFrameworks
Visual Studio Project System determines the list of valid TargetFrameworks to show
in the Project properties by querying SupportedTargetFramework values.


<!--
Supported (and unsupported) TargetFrameworks

Visual Studio Project System determines the list of valid TargetFrameworks to show
in the Project properties by querying SupportedTargetFramework values.

The Project System does not refer to this list at this time for .NET Framework TFM's.
-->

<!--
<!--
When WindowsDesktop SDK is used without setting UseWPF or UseWindowsForms, it shows a (suppressible) warning and functions much
like Microsoft.NET.Sdk

Likewise, when WindowsDesktop SDK is used with a netcore TFM that is less than 3.0, it will simply act as if it were an
Microsoft.NET.Sdk project (and show a suppressible build-time warning).

Detect these situations and skip updates to @(SupportedTargetFramework) etc.
-->
<ItemGroup Condition=" '$(_RemoveUnsupportedTargetFrameworksForWindowsDesktop)' == 'true' ">
Microsoft.NET.Sdk project (and show a suppressible build-time warning).

<!--
Detect these situations and skip updates to @(SupportedTargetFramework) etc.
-->
<ItemGroup Condition=" '$(_RemoveUnsupportedTargetFrameworksForWindowsDesktop)' == 'true' ">
<!--
Windows Forms and WPF are supported only on .NET Core 3.0+
-->
<_UnsupportedNETCoreAppTargetFramework Include=".NETCoreApp,Version=v1.0" />
Expand All @@ -140,17 +138,17 @@
<_UnsupportedNETStandardTargetFramework Include="@(SupportedNETStandardTargetFramework)" />

<!--
Windows Forms was supported since .NET Framework 1.0, and is currently supported on
.NET Framework 2.0+.
Windows Forms was supported since .NET Framework 1.0, and is currently supported on
.NET Framework 2.0+.

WPF is supported on .NET Framework and WPF are supported on .NET Framework 3.0+

In practice, the WindowsDesktop SDK is only supported on .NET Framework 3.0+ - this is controlled
by $(_WindowsDesktopSdkTargetFrameworkVersionFloor), defined as 3.0, which applies to both .NETFramework
and .NETCore.
Here, we will encode .NET Framework 3.0 as the lowest supported version for both Windows Forms and WPF.

Here, we will encode .NET Framework 3.0 as the lowest supported version for both Windows Forms and WPF.

The SDK does not define versions < 2.0 in @(SupportedNETFrameworkTargetFramework) list, so none of those
need to be excluded here - removing 2.0 would suffice.
-->
Expand All @@ -159,7 +157,18 @@
<SupportedNETCoreAppTargetFramework Remove="@(_UnsupportedNETCoreAppTargetFramework)" />
<SupportedNETStandardTargetFramework Remove="@(_UnsupportedNETStandardTargetFramework)" />
<SupportedNETFrameworkTargetFramework Remove="@(_UnsupportedNETFrameworkTargetFramework)" />

<SupportedTargetFramework Remove="@(_UnsupportedNETCoreAppTargetFramework);@(_UnsupportedNETStandardTargetFramework);@(_UnsupportedNETFrameworkTargetFramework)" />
</ItemGroup>

<!--
Workaround: https://github.com/microsoft/msbuild/issues/4948
Disable .NET Framework's inbox WinFX targets when using the SDK, since, we really don't use it's build logic
and is superseded by 'WindowsDesktop' SDK that provides it's own WinFX for both NETFX and CoreCLR targets.
Make it opt-out, just in case, if something fails or we don't want to use 'WindowsDesktop' SDK's version.
-->
<PropertyGroup>
<ImportFrameworkWinFXTargets Condition="'$(ImportFrameworkWinFXTargets)' == ''">false</ImportFrameworkWinFXTargets>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,53 +1,51 @@
<Project>

<PropertyGroup>
<_MicrosoftNetSdkWindowsDesktop>true</_MicrosoftNetSdkWindowsDesktop>
<_MicrosoftNETSdkWindowsDesktop>true</_MicrosoftNETSdkWindowsDesktop>
<EnableDefaultPageItems Condition="'$(EnableDefaultPageItems)' == ''">true</EnableDefaultPageItems>
<EnableDefaultApplicationDefinition Condition="'$(EnableDefaultApplicationDefinition)' == ''">true</EnableDefaultApplicationDefinition>
<DefaultXamlRuntime Condition="'$(DefaultXamlRuntime)'==''">Wpf</DefaultXamlRuntime>
</PropertyGroup>

<PropertyGroup>
<!--
WindowsDesktop SDK supports WPF and WinForms on
<!--
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

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',

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.
<!--
$(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.
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).
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).
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
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.
is safe to use here.
-->
<PropertyGroup>
<_TargetFrameworkVersionValue>$([MSBuild]::ValueOrDefault('$(_TargetFrameworkVersionWithoutV)', '$(_UndefinedTargetFrameworkVersion)'))</_TargetFrameworkVersionValue>
Expand All @@ -71,33 +69,28 @@
'$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)'">true</_RemoveUnsupportedTargetFrameworksForWindowsDesktop>
</PropertyGroup>


<Import Project="Microsoft.WinFX.targets" />

<ItemGroup Condition=" ('$(EnableDefaultItems)' == 'true') And ('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And
<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
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
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 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
Expand All @@ -110,7 +103,7 @@
<!-- 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"
<Target Name="CheckForDuplicatePageItems"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform;CoreCompile"
DependsOnTargets="CheckForDuplicateItems"
Condition="('$(UseWPF)' == 'true') And ('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And ('$(_TargetFrameworkVersionValue)' >= '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
Expand All @@ -133,29 +126,33 @@

</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"
<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
Condition="('$(TargetFrameworkIdentifier)' == '.NETCoreApp') And
('$(_TargetFrameworkVersionValue)' != '$(_UndefinedTargetFrameworkVersion)') And ('$(_TargetFrameworkVersionValue)' &lt; '$(_WindowsDesktopSdkTargetFrameworkVersionFloor)')">
<NetSdkWarning ResourceName="WindowsDesktopFrameworkRequiresVersion30" />
</Target>

<!-- Import WPF Build logic only when we don't import NETFX's WinFX targets -->
<Import Project="Microsoft.WinFX.targets" Condition="'$(ImportFrameworkWinFXTargets)' != 'true'"/>

</Project>
Loading