[ACCEPTED]-need help migrating winform to net 5-.net-5

Accepted answer
Score: 36

The error is clear:

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

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

Score: 0

That may happen if you share a project on 9 a DevOps Env like Azure.

To get the root 8 of that problem, I tried to build every 7 single project one by one and realized that 6 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 5 not build.

Including '-windows' in the TargetFramework 4 property will not help in this case.

I just 3 unloaded that project from the solution 2 and then I was able to rebuild it with no 1 errors again.

More Related questions