42

I have installed .NET 6.0 SDK and Visual Studio 2022. However, Visual Studio 2022 does not offer the ability to select .NET 6.0.

I know I can edit the project file with the target framework so please don't suggest that. This question is specifically around the Visual Studio 2022 UI.

dotnet sdks

Visual Studio 2022 UI

Edit 1:

.NET 6.0 Runtime has been selected in the Visual Studio Installer for Visual Studio 2022

Visual Studio Installer

Edit 2:

I can create .NET 6.0 projects but cannot seem to target .NET 6.0 in existing projects which were previously .NET 5.0.

New Project

Ishmaeel
  • 14,138
  • 9
  • 71
  • 83
Oliver
  • 35,233
  • 12
  • 66
  • 78
  • 5
    Any update on this? The same thing has happened to me. I installed VS 2022, .Net 6.0 Runtime was/is selected, .Net SDK was/is selected. I even went to the .Net download site and downloaded the SDK and installed it. Yet .Net 6 does not show up in the Target Framework dropdown and when I manually converted a project VS tells me that .Net 6 is not supported. My current guess is that it has something to do with a global.json file somewhere but I've gotta figure out where. – Steve Hiner Nov 12 '21 at 20:07
  • 2
    Strangely, .Net 6 does show up in the new project dialog. I was able to create a new ASP.Net project using 6.0. In that new project .Net 6 is listed in the target framework dropdown and the project will build. Switch back to an existing ASP.Net project and .Net 6.0 is no longer in the target framework dropdown. – Steve Hiner Nov 12 '21 at 20:18

6 Answers6

20

If your solution has a gobal.json file, you can either delete it or update the sdk version over there to the latest. At the point of this answer the latest .NET version is 6.0.0 with the sdk version as 6.0.100 (Latest sdk version could be found at the dotnet core site where you downloaded your sdk)

{
    "sdk": {
        "version": "6.0.100"
    }
}

Where to confirm your sdk version from your download

After you have done that, 'Unload' and 'Reload' your project and the latest .Net Core target should show up in the dropdown.

Anup Amin
  • 332
  • 1
  • 3
  • 3
    This was also the solution in my case. Remember that the `global.json` does not have to be placed in the same directory as the .csproj file, but may also be in a higher directory (in my case on the level of the .sln file), so I did not see it at first glance. – Andi Nov 23 '21 at 11:10
  • 2
    This was answer. We had a `global.json` file which was targeted to .NET 5. This was done so our build agents used the correct SDK when doing automated builds. Updating this to 6.0.100 allows .NET 6.0 to be selected in the VS2022 now. Thank you very much @Anup! Solid answer. – Oliver Nov 23 '21 at 11:49
  • 1
    It doesn't help me – Win4ster Feb 21 '22 at 15:39
10

I wonder if this is the same problem I've been struggling with - you can't change an existing project that is not in the 'sdk' format to net 6. But there is an upgrade assistant that will convert it for you.
See https://learn.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-winforms-framework

You have to install the upgrade assistant with

dotnet tool install -g upgrade-assistant

After installation, you can either analyze your project

cd "C:\your solution path"
upgrade-assistant analyze yourProject.csproj

or run the upgrade by

cd "C:\your solution path"
upgrade-assistant upgrade yourProject.csproj

The assistant will guide you through the steps.

Matt
  • 25,467
  • 18
  • 120
  • 187
  • 1
    That is good for upgrading an existing project. Afterwards you have the `upgrade-assistant` CLI available in the console. However, in my case, it didn't help, since the assistant didn't run through without issues. – Matt Jan 05 '22 at 13:42
  • Update: It took me some time, but I managed to upgrade an old WinForms project by using the `upgrade-assistant` - it is important to understand that it runs you through a couple of steps (like a workflow) and you need to review each step. If you're done with it, you can proceed by pressing "1" to start the next step - until the workflow completed. This way I could make it work and the project now runs with .NET 6. The CLI line is just for installing the assistant, after installation run `upgrade-assistant /?` to see the available options. You have to specify a project or solution. – Matt Jan 28 '22 at 10:01
  • 1
    I tried to upgrade a ```.NET Framework 4.6.1``` with the ```upgrade-assistant``` tool. The tool upgraded the project to ```netstandard20```. Did you experience the same issue? – wonderful world Apr 12 '22 at 02:46
  • @wonderfulworld , for me also same case it upgraded to netstandard20 and post that i am not able to change the target framework. Did you found the solution? – Ajay Kopperla Jun 30 '22 at 10:14
  • when we use the upgrade-assistant tool it creates two projects one with the backup and other the normal one. in my case normal one has netstandard20 , where as the back up is pointing to the net60 – Ajay Kopperla Jul 01 '22 at 07:11
  • this one worked, but why I cannot still see not 6.0 nor 7.0 in new project. and I do have them both installed. dotnet --version shows 7.0.102. – aleXela Feb 08 '23 at 00:36
8

During Visual Studio setup, you need to select the ".NET 6.0 Runtime". As can be seen in the screenshot, this option not only includes the runtime itself but also "templates for developing [...] .NET 6.0 applications".

screenshot

You can modify your installation by starting "Apps & Features" from the Windows start menu or by selecting Tools/"Get Tools and Features..." from the Visual Studio menu bar.

Heinzi
  • 167,459
  • 57
  • 363
  • 519
  • 3
    Thank you, this value is set in the Visual Studio Installer already. – Oliver Nov 11 '21 at 13:36
  • @Oliver: Hm, strange. Can you create a new .NET 6 project in Visual Studio? – Heinzi Nov 11 '21 at 13:47
  • I am busy doing a Visual Studio 2022 repair as maybe something with my installation went wrong. I'll test creating a new project when it is done. – Oliver Nov 11 '21 at 13:48
  • I have done the Visual Studio repair and updated to the latest and this is still an issue. No .NET 6.0 options shows in the dropdowns. – Oliver Nov 23 '21 at 08:05
  • 1
    @Oliver: Strange. Can you create a *new* .NET 6 project in VS 2022? – Heinzi Nov 23 '21 at 08:22
  • 3
    I can create .NET 6.0 projects, but it seems I cannot change the Target Framework from .NET 5.0 -> .NET 6.0 – Oliver Nov 23 '21 at 08:31
  • @Oliver: Hmm. It works on my machine, so you might have found a bug. If you're feeling generous, you could [report it](https://learn.microsoft.com/en-us/visualstudio/ide/how-to-report-a-problem-with-visual-studio?view=vs-2022). My personal experience with reporting VS bugs is mixed: Sometimes they are fixed rapidly, sometimes they are ignored for years. – Heinzi Nov 23 '21 at 08:45
  • @Oliver: I don't know if this is relevant, but, on my machine, I did *not* install the .NET 6 SDK. Maybe the stand-alone installer interferes with the version installed by Visual Studio. – Heinzi Nov 23 '21 at 08:46
  • I first tried on a vanilla VS 2022, I installed the standalone SDK in a hope to try fix the issue myself before logging it here. I'll give the report button a smash and see what happens. – Oliver Nov 23 '21 at 08:49
  • 2
    On a new PC, I have Installed VS Enterprise LTS 2022. I selected .NET 5 and .NET 6 runtimes in the installer. Also I installed .NET SDKs 3.1, 5.0, 6.0 for x64. Still I cannot see .NET 5 and .NET 6. What am I missing? – Matt Jan 05 '22 at 12:58
2

I have faced this issue when i used upgrade-assistant. it got upgraded to netstandard20. as part of the migration it has created the back up project also. when i open the back up project it was pointing to the net60.

Apart you can open the project file and target to the net6.0. try to unload and reload the project if it is not reflecting immediately.

Ajay Kopperla
  • 199
  • 2
  • 5
1

If none of the other answers work, double check you didn't open up the project in an old version of Visual Studio. I have VS 2022 installed but the default when double clicking a .sln file was still VS 2019. I only had .NET 6 installed for 2022.

Gabe
  • 837
  • 9
  • 13
  • Yes, and if you have a parallel installation there is a "Visual Studio Version Selector" APP installed from Microsoft where you can choose which version to use when opening SLN files. If you select the old version then VS remembers it and opens the old version of VS every time - causing trouble like here. – Matt Feb 15 '23 at 06:53
0

I install VS 2022 and cannot create any .NET 6 applications. I am trying to create a C# .NET 6 console application but VS only allows / shows .NET framework version up to 4.8.

I can edit and build a .NET 6 solution that someone else created but I cannot create one myself with my VS 2022 v17.2.6.

Mark Di Val
  • 81
  • 1
  • 7
  • 2
    So it turns out I CAN create a .NET 6 console application. I was using the "Console App (.NET Framework)" where I should have used the "Console App" option. – Mark Di Val Jul 17 '22 at 13:57