Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

NETSDK1045: the current .NET SDK does not support the target framework

ErrorNETSDK1045: The current .NET SDK does not support targeting .NET 7.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 7.0.

Short answer

The SDK that dotnet picked is older than the TargetFramework in your project. Run dotnet --list-sdks and dotnet --version, then install the SDK that matches, update global.json, or change the SDK image in your Dockerfile. A pinned global.json or an old path entry is the usual hidden cause.

  • Applies to .NET SDK 8, .NET SDK 9, .NET SDK 10
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Compare the project's target with the SDK dotnet really uses. Run it in the same folder and the same container as the build that fails.

    grep -n TargetFramework *.csproj
    dotnet --version
    dotnet --list-sdks
  2. 2Match what you see, then jump to its fix

    1. 1dotnet --list-sdks shows no SDK with the major version of TargetFrameworkThe installed SDK is older than the target frameworkFix
    2. 2dotnet --version prints an old version although a newer SDK is installedglobal.json pins an older SDKFix
    3. 3Installing a new SDK changes nothing, or dotnet runs from an unexpected folderPATH or MSBuildSDKPath points at an older SDK folderFix
    4. 4The .csproj looks right but the message names another versionDirectory.Build.props overrides the target frameworkFix

What does the error look like?

  • NETSDK1045: The current .NET SDK does not support targeting .NET 7.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 7.0.

Cause 1 of 4

The installed SDK is older than the target framework

1Check

Microsoft lists the installed SDKs with dotnet --list-sdks. The project can only target a framework the selected SDK supports, so the SDK needs the same or a newer major version.

grep -n TargetFramework *.csproj
dotnet --list-sdks

2Fix

Install the SDK for that version from the .NET download page. In a Dockerfile, use a build stage image with the matching SDK tag, for example mcr.microsoft.com/dotnet/sdk:8.0 for a net8.0 project.

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

3Verify

The build runs with the new SDK.

dotnet --version
dotnet build

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 4

global.json pins an older SDK

1Check

A global.json in the project folder or any parent folder can fix the SDK version. With a version and no rollForward, only that version and later patches are used. The file can sit anywhere up the directory tree.

find . .. ../.. -maxdepth 1 -name global.json
dotnet --info

2Fix

Change the version to the SDK you want, or let it roll forward. The sdk.version field needs a full version number; 8, 8.0 and wildcards are not valid.

{
  "sdk": {
    "version": "8.0.100",
    "rollForward": "latestFeature"
  }
}

3Verify

dotnet --version now shows a supported SDK.

dotnet --version

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 4

PATH or MSBuildSDKPath points at an older SDK folder

1Check

The build tools use PATH to find the SDK. Microsoft says the only dotnet entry on PATH should be the top-level dotnet folder. MSBuildSDKPath, when set, overrides the default and may point at an old SDK.

which -a dotnet
echo "$MSBuildSDKPath"
echo "$PATH"

2Fix

Remove entries that point inside an old SDK folder, unset MSBuildSDKPath, then open a new shell.

unset MSBuildSDKPath

3Verify

dotnet --list-sdks lists the SDK you installed and dotnet build works.

dotnet --list-sdks
dotnet build

Confirmed by learn.microsoft.com

Did this fix it?

Cause 4 of 4

Directory.Build.props overrides the target framework

1Check

A Directory.Build.props file in the solution folder or above can set TargetFramework or MSBuildSDKPath for every project below it.

find . .. -maxdepth 2 -name Directory.Build.props -exec grep -H -E 'TargetFramework|MSBuildSDKPath' {} +

2Fix

Remove or correct the TargetFramework or MSBuildSDKPath setting that conflicts with your project.

<!-- Directory.Build.props: delete or correct lines like these -->
<TargetFramework>net8.0</TargetFramework>
<MSBuildSDKPath>/old/sdk/path</MSBuildSDKPath>

3Verify

The build reports no NETSDK1045.

dotnet build

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Keep the SDK image tag in the Dockerfile in line with TargetFramework when you upgrade a project.
  • Use rollForward in global.json for CI so a newer feature band is accepted.
  • Print dotnet --info at the start of every CI build.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

dotnet stops with 'the folder host/fxr does not exist' on Ubuntu

A fatal error occurred. The required library libhostfxr.so could not be found.

This error nearly always means .NET packages came from two different package feeds, usually Ubuntu's own and Microsoft's, and each put files in a different place.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.