ASP.NET Core TargetFramework mismatch (NETSDK1045) in CI
The .NET SDK installed on the runner is older than the TargetFramework your project declares, so the SDK refuses to build it. Install the matching SDK with setup-dotnet (or global.json) so CI targets the same framework you do locally.
What this error means
The build fails with "error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0. Either target .NET 7.0 or lower, or use a version of the .NET SDK that supports .NET 8.0."
error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0.
Either target .NET 7.0 or lower, or use a version of the .NET SDK that supports
.NET 8.0.Common causes
The runner SDK is older than the TargetFramework
CI provisioned an SDK that predates net8.0 (or whatever you target), so it cannot build the project.
global.json pins an SDK CI does not have
A global.json requests an SDK version not installed on the runner, so the resolved SDK is too old for the target.
How to fix it
Install the matching SDK with setup-dotnet
- Add setup-dotnet with the version your TargetFramework needs.
- Match
dotnet-versionto the SDK band for your target (for net8.0 use 8.0.x). - Commit a
global.jsonif you need an exact SDK across environments.
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'Align global.json with an available SDK
Pin an SDK version that setup-dotnet installs, or allow roll-forward so a compatible SDK is used.
{
"sdk": { "version": "8.0.400", "rollForward": "latestFeature" }
}How to prevent it
- Install the SDK band that matches your TargetFramework with setup-dotnet.
- Keep global.json in sync with the SDK CI actually provisions.
- Do not rely on launchSettings.json in CI; it is a local dev file, not read by the build.