Reputation: 397
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
I've got my target framework set to the following:
<TargetFramework>net5.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
any help would be appreciated
Upvotes: 19
Views: 10990
Reputation: 4040
That may happen if you share a project on a DevOps Env like Azure.
To get the root of that problem, I tried to build every single project one by one and realized that One of my teammates added a new WinForm project into our API project
.csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows')) and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net6.0-windows</TargetFrameworks>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
I was using a Mac so I could not build.
Including '-windows' in the TargetFramework property will not help in this case.
I just unloaded that project from the solution and then I was able to rebuild it with no errors again.
Upvotes: 0
Reputation: 15
Change target framework to right version in project properties.
Upvotes: -4
Reputation: 28826
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
Upvotes: 38