dotnet "NETSDK1045: does not support targeting .NET 9.0" in CI
NETSDK1045 fires when a project’s TargetFramework is newer than the SDK installed on the runner. An older SDK has no knowledge of the newer framework moniker and refuses to build it.
What this error means
Build fails with NETSDK1045 stating the current SDK does not support targeting the requested framework (e.g. net9.0), and suggests targeting lower or upgrading the SDK. It reproduces on that runner because the SDK simply predates the framework.
error NETSDK1045: The current .NET SDK does not support targeting .NET 9.0.
Either target .NET 8.0 or lower, or use a version of the .NET SDK that supports .NET 9.0.Common causes
Project targets a framework newer than the SDK
A net9.0 project needs the 9.0 SDK or newer. On a runner with only the 8.0 SDK, the build cannot target 9.0.
Runner image SDK lags the project
The project was bumped to a newer TFM but the CI image (or global.json pin) still resolves an older SDK that does not understand it.
How to fix it
Install an SDK that supports the framework
Pin an SDK at least as new as the target framework.
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x' # supports net9.0 and earlierOr lower the TargetFramework to a supported one
If you must stay on an older SDK, target a framework it supports.
<TargetFramework>net8.0</TargetFramework>How to prevent it
- Keep the CI SDK at or above every project’s
TargetFramework. - Bump the SDK and the target framework together across the solution.
- Pin the SDK with
global.jsonso selection is deterministic and visible.