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
Asked Answered
C

13

69

I know this is a duplicate question. But I have tried every mentioned solution and didn't get resolved.

I have a dotnet c# application. when I run the application I got the below-mentioned error

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.

All the following solutions I have tried

  1. Download and install the dotnet-SDK-6.0.300 version.
  2. Updated the VS-2019 and checked the " Use preview of the .NET SDK (required restart)

Windows Edition: Windows 11

Still, it's not working. Got the same error. Help me out of this.

Conservatoire answered 24/5, 2022 at 14:53 Comment(4)
I have this issue as well, did the same things, got the same results. In my case, I'm trying to get a clone of ImGui.NET to build.Noahnoak
@BryanEdds Please check the verified answer of this question for the solutionConservatoire
Generally happens when global.json has lesser version than the version targetted in csproj.Taddeo
Related post - The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 2.0 or lower, or use a .NET SDK that supports .NET Core 2.1Stereo
C
121

.NET 6 is supported with Visual Studio 2022 and Visual Studio 2022 for Mac. It is not supported with Visual Studio 2019, Visual Studio for Mac 8, or MSBuild 16. If you want to use .NET 6, you will need to upgrade to Visual Studio 2022 (which is also now 64-bit).

Conservatoire answered 30/5, 2022 at 5:42 Comment(7)
I am using Visual Studio 2022 for Mac 17.0.2 and am still experiencing the issue. This is a large project that we just upgraded from 5 to 6. My target framework: <TargetFrameworks>net6.0</TargetFrameworks> My global.json { "sdk": { "version": "6.0.300" } }Tonkin
To add some clarity as to how I experienced this. I have both VS2022 and VS2019 installed on my machine and I created the project in 2022, but when I double clicked to open the sln file, it opened 2019. I hadn't realized it did that, so I experienced the error message in this question.Familial
I am using VS 2019 on windows 10, this answer doesn't apply to windows usersWatermark
I have VS 2019 and VS 2022, build is successful on VS 2022 and failing on VS 2019. I am windows 11 user. Installing VS 2022 solved my problem. Thanks for the answer @ConservatoireCutcliffe
There were some indications that allowing pre-release in VS2019 may server to override the 2022 requirement. I haven't been able to verify. See response from Alexey L: dotnet.microsoft.com/en-us/download/dotnet/6.0 learn.microsoft.com/en-us/answers/questions/620284/…Defluxion
I had the same issue with VisualStudio 2022 and, the .net 8 preview, and updating VS to the latest version fixed the issue.Lycanthropy
In my case I had both VS2019 and VS2022 on my PC, and I started VS2019 by mistake. The environment looked the same so it took me half an hour to figure out this simple issue!Benton
G
12

I experienced this issue while upgrading a project from .NET 5 to .NET 6, using Visual Studio 2022.

In my case, the problem was the existence of a global.json file fixing the SDK version:

{
  "sdk": {
    "version": "5.0.0",
    "rollForward": "latestMinor"
  }
}

The error was gone simply by updating that file to 6.0.0.


UPDATE:

I found this problem again when updating a project from .NET Core 3.1 to .NET 6. In this case, it was caused by these lines in the *.sln file, which pointed to Visual Studio 2019:

VisualStudioVersion = 16.0.28922.388
MinimumVisualStudioVersion = 16.0.0.0

Upgrading them to point to Visual Studio 2022 fixed the build in my CI system:

VisualStudioVersion = 17.0.0.0
MinimumVisualStudioVersion = 17.0.0.0
Griseofulvin answered 12/1, 2023 at 15:0 Comment(4)
This got me too when trying to move from 5 to 6 as well. I'm not sure where this file came from, as it wasn't checked in to source control. Removing the file worked to allowed me to build against 5, 6, and 7. So far the file hasn't recreated itself.Minton
Had given up. IDE was not showing .NET 6.0 in the Target framework field. I had even reinstalled the framework. Many thanks.Mantoman
If you are still getting errors, do a dotnet tool restore after changing the Visual Studio Terminal window. Worked for me.Turenne
I had this happen to me with a global.json that was sitting above the folder I was working on.Kindness
R
9

.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

Reformed answered 2/11, 2022 at 11:42 Comment(0)
B
5

If you are trying to set up docker, open your ".csproj" file and change the Target Framework version to be the same as the one in your Dockerfile

<PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileContext>..\..\..</DockerfileContext>
</PropertyGroup>
Booma answered 30/8, 2022 at 7:22 Comment(1)
Didn't see the other comments but a 1 character change seems the most efficient, great jobOvermaster
K
2

On AWS CodeBuild if you want to run (not yet supported on AWS) .NET 7.0, use this buildspec. The channel needs to be STS

phases:
  install:
    commands:
      - /usr/local/bin/dotnet-install.sh --channel STS

  build:
    commands:
      - dotnet restore
      - dotnet build --configuration Release BackendApi.csproj
      - dotnet publish --configuration Release BackendApi.csproj --output ./publish
Kittykitwe answered 1/3, 2023 at 0:20 Comment(0)
A
2

Just to add another reason why this might be happening. In our case, definitely having the correct SDK installed, definitely targeting it correctly, and even having a global.json file with the correct sdk version in it did not work. The global.json file was definitely found, but ignored. This was on a build server.

Turns out, someone had defined an environment variable

MSBuildSDKsPath=C:\Program Files\dotnet\sdk\5.0.402\Sdks

... and dotnet stubbornly wanted to use that SDK. I have not found that documented anywhere. Unsetting that environment variable did the trick.

Anhydride answered 9/8, 2023 at 3:3 Comment(1)
Microsoft lists this environment variable as one of the official possible reasons for the SDK error: learn.microsoft.com/en-us/dotnet/core/tools/sdk-errors/…Benton
U
2

If you encounter an error related to .NET 8, verify your Visual Studio version. Support for .NET 8 begins with Visual Studio 17.8.

Unspeakable answered 16/1 at 12:57 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Shirr
This actually solved the issue. I was using 17.4, which is still "2022", so I thought 8.0 should work, but it didn't. Now it does. Thanks!Leaved
C
2

If you receive the error "The current .NET SDK does not support targeting .NET 8.0. Either target .NET 7.0 or lower...", while running an app created with .Net 8.

  1. Make sure that you download .NET 8 SDK from https://dotnet.microsoft.com/en-us/download/dotnet/8.0

  2. From Visual Studio, click on Help > Check for Update to update the version of Visual Studio 2022 to 17.8 or higher.

Calloway answered 25/2 at 0:6 Comment(0)
B
1

I found an interesting reason to workaround. I have checked all the above instructions, using VS 2022, installed .Net 6, taking updates but still, issues exist then I check my Dockerfile and found an interesting reason, there was pointing wrong .net version but I set .net version 5 to 6 through project property. I just pointed to .net 6 in the docker file as a base and the build now working fine.

Sample base and build .net 6 command

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
and for build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
Bearnard answered 8/8, 2022 at 11:40 Comment(1)
I had same issue. I copied file from my old project and in that I was using .net core 5.0 and in newer project I was using 7.0. so I have to update the version and it started working for me.Coating
C
0

I experienced the same issue while building the docker image after upgrading from .NET 5 to 6. I solved it by creating a new docker image and building it again.

Collector answered 28/10, 2022 at 11:56 Comment(0)
S
0

Got this error just after upgrading from vs2019 to vs2022. Just restarted my workstation and it was gone.

Swingle answered 17/1, 2023 at 7:46 Comment(1)
Also, I was getting this error, and realize I opened the VS 2019 instead of 2022 - user errorBergamo
A
0

For me, I accidentally had the "Build with MSBuild on Mono" checkbox checked.

This is located in Solution Properties > Build > General

Archangel answered 12/6, 2023 at 19:11 Comment(0)
M
0

I had the same error but with .net 8/6. My issue was that we had 2 global.json files, each with its own version. After I deleted the one with .net 6, everything worked fine.

Margaret answered 6/12, 2023 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.