Error when building .exe with netcoreapp31, net 6.0 and net 7.0

Tool: Visual Studio 2019 Powershell Pro tools
Version: 2023.2.1

Hi,

I have to build .exe with netcoreapp31 or net6.0 or net 7.0 because application is flagged as malware with net 4.8 but building always fail. I have tried to install all required .NET libaries with no result.

Error:
C:\Program Files\dotnet\sdk\7.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(134,5): warning NETSDK1182: Targeting .NET 6.0 or higher in Visual Studio 2019 is not supported. [C:\Users\admin\AppData\Local\Temp\0e9cc0acf086457296e55262e41631da\App.csproj]
C:\Program Files\dotnet\sdk\7.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(146,5): 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. [C:\Users\admin\AppData\Local\Temp\0e9cc0acf086457296e55262e41631da\App.csproj]
1 Warning(s)
1 Error(s)

Time Elapsed 00:00:00.58

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\PowerShell Tools for Visual Studio\PowerShellTools.targets(7,5): error : Failed to build.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========


with these settings I got following error:

Build started…
------ Build started: Project: App, Configuration: Debug Any CPU ------
Checking license
OutputPath is C:\Users\admin\source\repos\App\App\bin\Debug
Bundling App.ps1
Parsing file App.ps1.
Checking path $ConfigPath for XAML.
Checking path $ConfigPath for XAML.
Checking path $ConfigPath for XAML.
Packaging C:\Users\admin\AppData\Local\Temp\App.ps1
Creating temp directory: C:\Users\admin\AppData\Local\Temp\84f990b590f44070949f7adbd86ccab2
Packaging modules…
Checking dotnet version.
Checking dotnet SDK version.
7.0.202

	.NET SDK Version: 7.0.202

	Creating package project.
	Using .NET Framework version: netcoreapp31
	  Determining projects to restore...

Restored C:\Users\admin\AppData\Local\Temp\84f990b590f44070949f7adbd86ccab2\App.csproj (in 72 ms).

	  Determining projects to restore...

Restored C:\Users\admin\AppData\Local\Temp\84f990b590f44070949f7adbd86ccab2\App.csproj (in 72 ms).

	Packaging C:\Users\admin\AppData\Local\Temp\App.ps1 -> C:\Users\admin\source\repos\App\App\bin\Debug\App.exe
	MSBuild version 17.5.0+6f08c67f3 for .NET

Determining projects to restore…
All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\7.0.202\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly “System.Windows.Forms”. Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\Users\admin\AppData\Local\Temp\84f990b590f44070949f7adbd86ccab2\App.csproj]
App → C:\Users\admin\source\repos\App\App\bin\Debug\App.dll

Build succeeded.

C:\Program Files\dotnet\sdk\7.0.202\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly “System.Windows.Forms”. Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\Users\admin\AppData\Local\Temp\84f990b590f44070949f7adbd86ccab2\App.csproj]
1 Warning(s)
0 Error(s)

Time Elapsed 00:00:00.93

	MSBuild version 17.5.0+6f08c67f3 for .NET

Determining projects to restore…
All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\7.0.202\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly “System.Windows.Forms”. Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\Users\admin\AppData\Local\Temp\84f990b590f44070949f7adbd86ccab2\App.csproj]
App → C:\Users\admin\source\repos\App\App\bin\Debug\App.dll

Build succeeded.

C:\Program Files\dotnet\sdk\7.0.202\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly “System.Windows.Forms”. Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\Users\admin\AppData\Local\Temp\84f990b590f44070949f7adbd86ccab2\App.csproj]
1 Warning(s)
0 Error(s)

Time Elapsed 00:00:00.93

	Output: C:\Users\admin\source\repos\App\App\bin\Debug\App.exe

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========