.Net 5 RC2, WinForms, NETSDK1136, NETSDK1137

After installing .Net 5 rc2 I tried making a WinForms project using Visual Studio Preview. It looked like it worked straight away but the default target framework was .Net Core 3.1:

After changing from 3.1 to 5 I then got a compilation error:

error NETSDK1136: The target platform must be set to Windows (usually by including '-windows' in the TargetFramework property) when using Windows Forms or WPF, or referencing projects or packages that do so.

To fix this I unloaded and then edited the project file (within Studio):

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
</Project>

This changed fixed the target platform problem. The compiler then displayed a warning/comment saying that the project SDK could be updated:

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'

So I edited the project file again and changed to:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
</Project>

With these two mods I now had an error and warning free .Net 5 RC2 WinForms project – my first ever!

Walkthrough:

Leave a comment