Reputation: 2467
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
Windows Edition: Windows 11
Still, it's not working. Got the same error. Help me out of this.
Upvotes: 77
Views: 192249
Reputation: 1
I will just add on that I made sure targetframework was .net9.0 in all projects. It didn't build, just complained about The current .NET SDK does not support targeting .NET 9.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 9.0.
Just changing base and build in the DockerFile from 6.0 to 9.0 fixed the problem. The error message wasn't even close to what the issue was.
Upvotes: 0
Reputation: 2695
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
Upvotes: 15
Reputation: 2189
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.
Make sure that you download .NET 8 SDK from https://dotnet.microsoft.com/en-us/download/dotnet/8.0
From Visual Studio, click on Help > Check for Update to update the version of Visual Studio 2022 to 17.8 or higher.
Upvotes: 5
Reputation: 41
If you encounter an error related to .NET 8, verify your Visual Studio version. Support for .NET 8 begins with Visual Studio 17.8.
Upvotes: 4
Reputation: 733
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.
Upvotes: 0
Reputation: 999
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.
Upvotes: 4
Reputation: 2023
For me, I accidentally had the "Build with MSBuild on Mono" checkbox checked.
This is located in Solution Properties > Build > General
Upvotes: 0
Reputation: 1846
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
Upvotes: 2
Reputation: 11
Got this error just after upgrading from vs2019 to vs2022. Just restarted my workstation and it was gone.
Upvotes: 0
Reputation: 2050
.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.
Upvotes: 9
Reputation: 147
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.
Upvotes: 0
Reputation: 61
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>
Upvotes: 5
Reputation: 1199
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
Upvotes: 1
Reputation: 2467
.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).
Upvotes: 129