jithu
jithu

Reputation: 2467

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

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.

Upvotes: 77

Views: 192249

Answers (14)

Curt
Curt

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

Tao Gómez Gil
Tao Gómez Gil

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

Auguste
Auguste

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.

  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.

Upvotes: 5

user23252939
user23252939

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

Alex Albu
Alex Albu

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

Barbara
Barbara

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

Ben
Ben

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

realPro
realPro

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

Nim.th
Nim.th

Reputation: 11

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

Upvotes: 0

Bhadresh Patel
Bhadresh Patel

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. enter image description here

Upvotes: 9

Cheruiyot A Kirui
Cheruiyot A Kirui

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

CutCopyPaste
CutCopyPaste

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

Mahi
Mahi

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

jithu
jithu

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

Related Questions