Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

need help migrating winform to net 5

I'm porting a winform app from net core 3.1 to net 5 and getting the following error.

Severity Code Description Project File Line Suppression State 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. PublicOutput.core C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets 369

This is the section of Microsofts.net.sdk.DefaultItems.targets that this is referring to.

  <Target Name="_CheckForInvalidWindowsDesktopTargetingConfiguration"
        BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
        Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '5.0')) and ('$(UseWindowsForms)' == 'true' or '$(UseWPF)' == 'true')">
    <NETSdkError Condition="'$(TargetPlatformIdentifier)' != 'Windows'"
                 ResourceName="WindowsDesktopTargetPlatformMustBeWindows" >

I don't understand the error and the link where the error sends me is not helpful

https://docs.microsoft.com/en-us/visualstudio/?f1url=%3FappId%3DDev16IDEF1%26l%3DEN-US%26k%3Dk(NETSDK1136)%26rd%3Dtrue&view=vs-2019

I've got my target framework set to the following:

    <TargetFramework>net5.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>

any help would be appreciated

like image 600
Michael Leipper Avatar asked Nov 11 '20 12:11

Michael Leipper


1 Answers

The error is clear:

The target platform must be set to Windows (usually by including '-windows' in the TargetFramework property) when using Windows Forms or WPF,

so change <TargetFramework>net5.0</TargetFramework> to <TargetFramework>net5.0-windows</TargetFramework> as written in docs

like image 137
magicandre1981 Avatar answered Sep 18 '22 12:09

magicandre1981