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

Viewed 15849

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.

3 Answers

.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).

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>

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
Related