.NET "error NETSDK1045: current SDK does not support targeting" in CI
The project targets a .NET version newer than the SDK installed on the runner. NETSDK1045 means you must install a matching (or newer) SDK, because an SDK cannot build a framework it predates.
What this error means
dotnet 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 target framework
The image or setup-dotnet step provides an SDK that predates the TargetFramework, so it cannot build it.
A global.json pins an older SDK
A global.json rolls the SDK down to a version that does not support the project's framework.
How to fix it
Install the matching SDK in CI
- Set
setup-dotnetto the SDK major that supports the target framework. - Remove or update a
global.jsonthat pins an older SDK. - Re-run the build.
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'Align global.json with the target
If you keep a global.json, set it to an SDK that supports the framework.
{
"sdk": { "version": "8.0.100", "rollForward": "latestFeature" }
}How to prevent it
- Provision the SDK major that matches your target framework in CI.
- Keep
global.jsonin step with the frameworks you build. - Pin
setup-dotnetversions so the SDK is deterministic.