76

I've been struggling to change an ASP.NET Core Web API project's target framework to .NET 6 which was started using target framework .NET 5. I've already tried a few options but couldn't find the .NET 6 Framework listed in the target dropdown.

  1. I am using Microsoft Visual Studio Enterprise 2019 Version 16.11.3.
  2. I've installed .NET 6.0.0-rc.2.21480.5. which is verified through dotnet --version.
  3. Enabled "Use previews of the .NET Core SDK", and restarted the program.
  4. restarted workstation several times & still no luck.
TylerH
  • 20,799
  • 66
  • 75
  • 101
Yasir Arafat
  • 938
  • 1
  • 6
  • 9

15 Answers15

62

.NET 6 and later are not supported in Visual Studio 2019. You might make it work by manually editing your project file, but for a fully supported experience you should upgrade to Visual Studio 2022.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
38

You don't need to use the dropdown - open your .csproj file and change target framework manually:

<TargetFramework>net6.0</TargetFramework>

As for dropdown - it seems that there is some bug in VS - I have 16.11.5 installed alongside VS 2022 preview and the "Use previews of the .NET Core SDK" flag enabled and even project using .NET 6 (which builds and runs via VS2019). Also despite missing .NET 6 in the project properties the new project wizard has it.

Visual Studio 2019 does not support .NET 6 (also see VS support in the release notes). Install VS 2022 for full .NET 6 support.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
  • Thanks for your response! I did that too, but the build fails for that case displaying "NETSDK1045: The current .NET SDK does not support 'newer version' as a target." error msg! – Yasir Arafat Oct 29 '21 at 20:57
  • @YasirArafat check for `global.json` in your project. Also try `dotnet build` from the console. – Guru Stron Oct 29 '21 at 21:09
  • @YasirArafat also try installing the preview version of 2022 (and try building from VS 2019) - maybe this will also help. – Guru Stron Oct 29 '21 at 21:14
  • there is no global.json. `dotnet build` command was successful, but the solution doesn't run! besides, I found new info as NETSDK1182: Targeting .NET 6.0 in Visual Studio 2019 is not supported! Already up to installing the 2022 RC3! – Yasir Arafat Oct 29 '21 at 21:23
  • This works, but ASP.NET 6 projects cannot be started from within VS2019, the app throws `InvalidOperationException: The view 'Index' was not found`. Because of the new way .NET6 compiles razor views – Alex from Jitbit Feb 15 '22 at 16:42
10

To get Visual Studio 2019 to work with .NET 6 all you have to do is the following:

  • Install the .NET 6 SDK: https://dotnet.microsoft.com/download
  • Open your VS project that you want to switch to .NET 6
  • Build your project with .NET 5(+)
  • go into the project dir and find your project file: .csproj
  • open the project file in notepad or Notepad++, basically any txt editor and find the node: <TargetFramework>
  • If you built your project with .NET 5(+) it will read as: <TargetFramework>net5.0-windows</TargetFramework>
  • Simply switch the value to: net6.0-windows 5 changed to 6
  • Your TargetFramework entry should be edited to: <TargetFramework>net6.0-windows</TargetFramework>
  • Now save your project file
  • Next simply boot up Visual Studio 2019 and the target project you just modified to run .NET 6.
  • Do a clean on your project under the [ Build ] menu item
  • Now re-build your project and you are good to go \m/ :) \m/

Note I am using a Windows platform example the same concept should work for Linux etc just look at what the .NET 5 node looks like for the <TargetFramework> and just swap in the 6 instead of 5 and keep what ever other txt is in the value. I have not tried other platforms other than Windows but I am sure it will work as well.

I have swapped various projects and complicated ones and .NET 6 works perfectly in all cases on Visual Studio 2019!

TylerH
  • 20,799
  • 66
  • 75
  • 101
valcan_s
  • 109
  • 4
  • 4
    This doesn't seem to work anymore? I get a clear error in VS2019 `Targeting .NET 6.0 in Visual Studio 2019 is not supported.` It's unfortunate, because VS2022 has serious issues with Blazor projects right now. – Mmm Dec 07 '21 at 21:40
  • 4
    Tested with Version 16.11.9, app builds and launches fine. I do get a similar warning but no error. ```warning NETSDK1182: Targeting .NET 6.0 in Visual Studio 2019 is not supported.``` – Jos Jan 25 '22 at 09:22
  • VS 2019 16.11.10 gives a solid error – Steve Feb 24 '22 at 14:26
  • VS 16.11.106 x86: complainging (warnings) a lot, but seems to work fine. – Xan-Kun Clark-Davis Mar 20 '22 at 11:08
7

The problem is not with the version of visual studio, but the version of the .NET 6 SDK used. According to Microsoft's website:

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.109 (for latest .NET 6.0.9 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.19.

The solution is to install and use .NET 6 SDK version 6.0.2xx or lower. Then all the old solutions posted here will work.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Maxter
  • 716
  • 7
  • 15
6

Updating Visual Studio to version 16.11.7 solved my problem.

But first you have to check the checkbox: Tools > Options > Environment > Preview Features > Use Preview Of .Net SDK (requires restart)

TylerH
  • 20,799
  • 66
  • 75
  • 101
Ehsan
  • 85
  • 9
3

Edit the file %PROGRAMFILES%\dotnet\sdk\[VERSION]\minimumMSBuildVersion and change 17.0.0 to 16.0.0.

The project's dropdown in VS 2019 then works and allows selecting .NET 6.0

Trader
  • 31
  • 2
2

image

Dotnet 6.0 is only supported in visual studio 2022. you can check details from here: https://dotnet.microsoft.com/en-us/download/dotnet/6.0

TylerH
  • 20,799
  • 66
  • 75
  • 101
Hgrbz
  • 185
  • 3
  • 12
2

Another potential reason might be a global.json, I forgot we had one and it prevented .NET 5/6 from showing up in the dropdown. As soon as I fixed that by pointing it to the new version, it showed up.

Thomas Glaser
  • 1,670
  • 1
  • 18
  • 26
  • This was my issue. My global.json was pointed to 3.1.0 .net core instead of { "sdk": { "version": "6.0.300" } } – tvb108108 Jun 04 '22 at 23:55
2

.NET SDK 6.0.100 is almost correctly working with Visual Studio 2019 v16.10.3. Microsoft lies that it is VS 2022-only. :) Theoretically, newer versions should work too, but some people saying that it was broken near VS 16.11.10 or in latest .NET 6.0.x SDKs (correct me, please, if it is not). I currently haven't checked.

To set target .NET runtime version to 6.0, enter <TargetFramework>net6.0</TargetFramework> version in project's .csproj file directly. This will give empty dropdown list line in project's properties window, but, however, the project will build for .NET 6.0. This means also that all projects, initially written for .NET 6, should open on VS 2019 too (if they don't use new C# 10 features).

When building the project under Visual Studio (not via dotnet command line), it will add warning NETSDK1182: Targeting .NET 6.0 in Visual Studio 2019 is not supported message. It does not break compiling and debugging, but can be easily thrown out too. Open .csproj file again, and add <NoWarn>$(NoWarn);NETSDK1182</NoWarn> to an PropertyGroup.

1

For me the cause was the 32 bit(!) installation of dotnet.exe in the c:\Program Files (x86)\... folder.

What I've done?

  • As a diagnostic step I run dotnet --list-sdks, it listed nothing
  • Although I was convinced I have dotnet sdks (I working daily basis with .NET, and now installed VS 2022, how it would be possible not having any SDKs?
  • Anyway, I installed the latest release of .NET 6 SDK
  • As a diagnostic step I run dotnet --list-sdks, still nothing
  • I run where dotnet.exe and it turned out that it came from c:\Program Files (x86)\...
  • Renamed the 32 versions folder, and all solved.
g.pickardou
  • 32,346
  • 36
  • 123
  • 268
1

You must edit the file %PROGRAMFILES%\dotnet\sdk\[VERSION]\minimumMSBuildVersion with version of msbuild supported by VS 2019.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 18 '22 at 15:45
1

According to Microsoft resources, you can only use dot net core 6 Preview-1, 2, 3 And 4 in Visual Studio 2019. this link

topcool
  • 2,498
  • 7
  • 28
  • 52
1

.NET 6 is supported with Visual Studio 2022 and Visual Studio 2022 for Mac. It is not supported with Visual Studio 2019. If you want to use .NET 6, you will need to upgrade to Visual Studio 2022.

Below is the official announcement by Microsoft community.

enter image description here

Bhadresh Patel
  • 1,671
  • 17
  • 18
0

.NET 6.0 is coming with VS 2022 ,install the new visual studio version and proceed

  • 2
    A lot of dev have no control over their visual studio version and must use what their boss is giving. – Maxter Oct 13 '22 at 16:27
0

The simple & perfect solution is, install all the sdks ,previews as necessary & it should be updated in global.json file of system level. In my case dotnet8 preview installed in machine,dotnet --list-sdks , dotnet --info all listing but still it was not allowing to change existing proejct version to latest 8 then only worked option is changing global.json file which exists in system user source repos level as like below. Hope many are searching for this or similar,this might help enter image description here

enter image description here