dotnet SDK / Runtime Mismatch - TargetFramework Not Supported
Your project targets a framework newer than the installed SDK can build. The build stops with NETSDK1045 because an older SDK has no knowledge of a newer TargetFramework.
What this error means
Build fails with NETSDK1045 stating the current SDK does not support targeting the requested net8.0 (or newer). It reproduces every run on that runner because the SDK simply predates the framework.
error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0.
Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 8.0.Common causes
SDK older than the TargetFramework
A net8.0 project needs the 8.0 SDK (or newer). On a runner with only the 6.0 SDK, the build cannot target 8.0.
Multiple SDKs but the wrong one is selected
A global.json or PATH order selects an older SDK even though a newer one is installed, so the newer framework is rejected.
How to fix it
Install an SDK that supports the framework
Pin an SDK at least as new as the framework you target.
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x' # supports net8.0 and earlierPin the right SDK with global.json
When several SDKs are installed, pin the one that supports your target framework.
{
"sdk": { "version": "8.0.401", "rollForward": "latestFeature" }
}Or lower the TargetFramework
- If you must stay on an older SDK, set
<TargetFramework>to a version it supports. - Confirm the SDK with
dotnet --versionmatches the framework requirement. - Prefer upgrading the SDK over downgrading the framework when possible.
How to prevent it
- Keep the CI SDK at or above every project’s
TargetFramework. - Pin the SDK with
global.jsonso selection is deterministic. - Upgrade SDKs and target frameworks together across the solution.