question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UseWpf should work with netframework as a TargetFramework

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

3reactions
kkwpsvcommented, Dec 9, 2020

You just need Microsoft.NET.Sdk.WindowsDesktop SDK. Then you can use UseWPF with .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’.

Microsoft.NET.Sdk works with only net5. When multitarget, we should use Microsoft.NET.Sdk.WindowsDesktop.

1reaction
kkwpsvcommented, Dec 9, 2020

@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?

No need to do this. There’s no warning with multitarget project when use Microsoft.NET.Sdk.WindowsDesktop.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WinForms and WPF apps use Microsoft.NET.Sdk
NET 5, the WinForms and WPF SDK has been unified with the .NET SDK ( Microsoft.NET.Sdk ). In addition, new target framework monikers...
Read more >
How Can I use .NET Framework 4.8 on an WPF Class ...
TargetFramework is in the .csproj file. Double click on the project in Visual Studio. For the project templates, the appropriate Workloads must ......
Read more >
Rider creates invalid project for ".NET Core / Desktop ...
NET.Sdk.WindowsDesktop. For these projects, setting TargetFramework to net5.0-windows and UseWPF or UseWindowsForms to true will automatically import the ...
Read more >
Upgrading Windows Desktop Applications with .NET Core 3
NET Framework and .NET Core: Before starting the migration, it's important to evaluate how compatible the application will be with .NET Core 3....
Read more >
Help with enabling C# 9 for .Net Framework project : r/csharp
I am working with a .Net Framework 4.8 project (non-sdk project file). ... some C# 8 and C# 9 features will work out...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found