NETSDK1045: the current .NET SDK does not support the target framework
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.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.
Fix it fast
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-sdks2Match what you see, then jump to its fix
- 1
dotnet --list-sdks shows no SDK with the major version of TargetFrameworkThe installed SDK is older than the target frameworkFix - 2
dotnet --version prints an old version although a newer SDK is installedglobal.json pins an older SDKFix - 3
Installing a new SDK changes nothing, or dotnet runs from an unexpected folderPATH or MSBuildSDKPath points at an older SDK folderFix - 4
The .csproj looks right but the message names another versionDirectory.Build.props overrides the target frameworkFix
- 1
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-sdks2Fix
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 build3Verify
The build runs with the new SDK.
dotnet --version
dotnet buildConfirmed by learn.microsoft.com
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 --info2Fix
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 --versionConfirmed by learn.microsoft.com
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 MSBuildSDKPath3Verify
dotnet --list-sdks lists the SDK you installed and dotnet build works.
dotnet --list-sdks
dotnet buildConfirmed by learn.microsoft.com
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 buildConfirmed by learn.microsoft.com
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
docker build fails with CS5001, no entry point found
error CS0017: Program has more than one entry point defined.
CS5001 means the compiler built an executable project and found no entry point.
4 causes, each with a fixServers
A containerized ASP.NET Core app says the framework Microsoft.AspNetCore.App was not found
Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
The app asks for a shared framework the final image does not have.
3 causes, each with a fixServers
docker build cannot find a local file or log in to a private NuGet feed
The parameter is incorrect
A Docker build sees only the build context, minus anything in .dockerignore, so files outside it are not found.
4 causes, each with a fixServers
ASP.NET Core container does not answer on the published port
The container is running and logs no error, but the mapped host port never answers
Since .NET 8 the ASP.NET Core container images listen on port 8080, not 80.
3 causes, each with a fixServers
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 fixServers
MSB1011 when dotnet build or publish runs inside a Docker build
dotnet build or dotnet publish fails in a RUN step of the Dockerfile
dotnet build and dotnet publish pick a project by searching the current folder.
3 causes, each with a fix