How to target .NET 6.0 with Visual Studio 2019?

john zyd 421 Reputation points
2021-11-09T09:12:02.417+00:00

Hello:
I know .NET 6.0 is released, but I don’t know how to create a WinForm App targeting .NET 6.0 with Visual Studio 2019 (Version 16.11.5) on Windows 10 (Version 21H1)
I can download the following packages:
.NET 6.0 SDK (v6.0.100) - Windows x64 Installer!
.NET 6.0 Desktop Runtime (v6.0.0) - Windows x64 Installer!
But when I create a WinForm App project, there is no place to target .NET 6.0.
Please give detailed instructions.
I know I can use Visual Studio 2022 can target .NET 6.0, but currently we can’t use Visual Studio 2022 yet, have to wait at least one year.
Thanks,

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,002 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,436 Reputation points
    2021-11-09T09:44:58.98+00:00

    First off, for proof the following works, the following Visual Studio Solution was created in VS2019, runs fine. As a side note I have samples for DateOnly and TimeOnly struct and a few other goodies.

    Under Options, Environment, Preview Features set Use previews of the .NET SDK to true, restart Visual Studio.

    Restart, in a Visual Studio solution create a new Windows Form app.

    To validate double click the project file in Solution Explorer and you should see

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

    Or create via PowerShell at the root folder of a Visual Studio solution

    dotnet new winforms --name WinApp1 --output WinApp1
    
    dotnet sln add .\WinApp1\WinApp1.csproj
    
    6 people found this answer helpful.

9 additional answers

Sort by: Most helpful
  1. Alexey Leonovich 96 Reputation points
    2022-09-26T08:45:55.363+00:00

    Visual Studio 2019 is officially unsupported for .NET 6.0 development but there is a workaround that is still working for today (October 2022):

    1. Install latest Visual Studio 2019 (I've tested on 16.11.20, 11 October 2022).
    2. Intall latest .NET SDK from 6.0.1xx SDK branch (I've tested on 6.0.110, for 6.0.10 runtime, 11 October 2022). It is vital to use this SDK branch because NETSDK1182 warning was transformed into a hard error in 6.0.3xx SDK branch. 6.0.2xx SDK branch is not getting updates anymore.
    3. Create new application of type you need targeting .NET 5.0. Compile it.
    4. Open .csproj file and change <TargetFramework>net50</TargetFramework> to <TargetFramework>net60</TargetFramework> (in some cases it can be net5.0-windows - so change it to net6.0-windows). Optionally add <LangVersion>preview</LangVersion> to be able to use C#9.0 syntax.
    5. Now you can compile, run and debug (don't pay attention to NETSDK1182 warning) some types of .NET 6.0 applications: class library, console, WinForms and WPF. ASP .NET Core applications doesn't compile for some reason, mybe there is some workaround but I don't have info about it.

    Detailed information about .NET SDK version:
    So finally looks like I've managed to find it out:
    NETSDK1182 warning was transformed into a hard error in .NET SDK 6.0.300 (for .NET 6.0.5 runtime, Visual Studio 17.2). So don't use 6.0.3xx SDK branch (looks like same is correct for 6.0.4xx, etc).
    6.0.2xx SDK branch is out of support (since Visual Studio 17.1 is out of support), but 6.0.1xx SDK branch is still supported (since Visual Studio 17.0 is supported till 11 April 2023).
    Latest one is .NET SDK 6.0.110 (for latest .NET 6.0.10 runtime) and with it Visual Studio 2019 can compile, run and debug some types of .NET 6.0 applications: class library, console, WinForms and WPF. ASP .NET Core applications doesn't compile but not because of NETSDK1182. Tested with latest Visual Studio 2019 16.11.20.
    Good luck.

    3 people found this answer helpful.

  2. Castorix31 85,711 Reputation points
    2021-11-09T09:29:42.81+00:00

    From the doc, it is not supported : Download .NET 6.0 :

    Visual Studio support
    Visual Studio 2022 (v17.0)
    Visual Studio 2019 for Mac (v8.10)

    If I set net6.0-windows in <TargetFramework> in .csproj, it does not work on my 2019 version :
    I get
    Error NETSDK1045 The current .NET SDK does not support targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0.

    and in the doc for .NET 6.0 SDK :
    This release is only compatible with Visual Studio 2022 (v17.0)

    2 people found this answer helpful.

  3. Jaliya Udagedara 2,821 Reputation points MVP
    2021-11-10T21:08:04.553+00:00

    @Castorix31 is correct. .NET 6 only supports following Visual Studio versions,

    • Visual Studio 2022 (v17.0)
    • Visual Studio 2019 for Mac (v8.10)

    More Information:
    Announcing .NET 6 — The Fastest .NET Yet
    https://dotnet.microsoft.com/download/dotnet/6.0


  4. Jeroen van Langen 1 Reputation point
    2022-08-01T14:05:27.03+00:00

    As I read here. Whole visual studio 2019 with dotnet 5 is obsolete. Can I have a part of my money back?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.