After some headache trying to achieve a multitarget project with net47 and net5.0-windows.
I would like to suggest that UseWpf should also work for net47.
My current project sadly has to look like this to make it "work".
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net47;net5.0-windows</TargetFrameworks>
<OutputType>WinExe</OutputType>
<RootNamespace>MyNamespace</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net47' ">
<StartupObject>MyNamespace.App</StartupObject>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net5.0-windows' ">
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net47' ">
<!--
<EmbeddedResource Update="Properties\Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
<Compile Update="Properties\Resources.Designer.cs" DesignTime="True" AutoGen="True" DependentUpon="Resources.resx" />
<None Update="Properties\Settings.settings" Generator="SettingsSingleFileGenerator" LastGenOutput="Settings.Designer.cs" />
<Compile Update="Properties\Settings.Designer.cs" DesignTime="True" AutoGen="True" DependentUpon="Settings.settings">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
-->
<Page Include="**\*.xaml" SubType="Designer" Generator="MSBuild:Compile" Exclude="App.xaml" />
<Compile Update="**\*.xaml.cs" SubType="Code" DependentUpon="%(Filename)" />
<ApplicationDefinition Include="App.xaml" SubType="Designer" Generator="XamlIntelliSenseFileGenerator" />
<Compile Update="App.xaml.cs" SubType="Code" DependentUpon="App.xaml" />
<Reference Include="System.Printing" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="PresentationFramework.Aero" />
<Reference Include="PresentationFramework.Aero2" />
<Reference Include="PresentationFramework.Luna" />
<Reference Include="PresentationUI">
<HintPath>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationUI\v4.0_4.0.0.0__31bf3856ad364e35\PresentationUI.dll</HintPath>
</Reference>
<Reference Include="ReachFramework" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
</Project>
My project file is a strange combination of this stackoverflow question
https://stackoverflow.com/questions/43693591/how-to-migrate-wpf-projects-to-the-new-vs2017-format
Other question, why is it necessary for me to provide the HintPath only for the assembly PresentationUI?
All the other assemblies can be found without an issue, but if I would drop the HintPath I would get a
14>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2123,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "PresentationUI". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
I am not sure if that is the correct place to post this issue.
If possible and I am wrong here move the issue to the correct place.
You just need Microsoft.NET.Sdk.WindowsDesktop SDK. Then you can use UseWPF with .net 4.7.
You just need
Microsoft.NET.Sdk.WindowsDesktopSDK. Then you can useUseWPFwith .net 4.7.
I thought we had just moved from Microsoft.NET.Sdk.WindowsDesktop to Microsoft.NET.Sdk in .net5's csproj sdk
warning NETSDK1137: It is no longer necessary to use the Microsoft.NET.Sdk.WindowsDesktop SDK. Consider changing the Sdk attribute of the root Project element to 'Microsoft.NET.Sdk'.
You just need
Microsoft.NET.Sdk.WindowsDesktopSDK. Then you can useUseWPFwith .net 4.7.I thought we had just moved from
Microsoft.NET.Sdk.WindowsDesktoptoMicrosoft.NET.Sdkin .net5's csproj sdkwarning NETSDK1137: It is no longer necessary to use the Microsoft.NET.Sdk.WindowsDesktop SDK. Consider changing the Sdk attribute of the root Project element to 'Microsoft.NET.Sdk'.
Microsoft.NET.Sdk works with only net5.
When multitarget, we should use Microsoft.NET.Sdk.WindowsDesktop.
@jespersh
Thanks for the info, didn't notice the warning when I tried it myself.
Seems like a prematurely opened the issue https://github.com/dotnet/try-convert/issues/343.
@kkwpsv
Can I define the SDK based on a condition?
So use Microsoft.NET.Sdk.WindowsDesktop on net47 but use Microsoft.NET.Sdk on net5-windows?
@kkwpsv
Can I define the SDK based on a condition?
So useMicrosoft.NET.Sdk.WindowsDesktopon net47 but useMicrosoft.NET.Sdkon net5-windows?
No need to do this. There's no warning with multitarget project when use Microsoft.NET.Sdk.WindowsDesktop.
Most helpful comment
Microsoft.NET.Sdkworks with only net5.When multitarget, we should use
Microsoft.NET.Sdk.WindowsDesktop.