"The current .NET SDK does not support targeting .NET X" in CI
The project targets a newer .NET version than the installed SDK can build. An 8.0 SDK cannot build a net9.0 project, for example. The fix is to install an SDK at least as new as the highest TFM you target - or lower the target.
What this error means
Build fails (often as NETSDK1045) saying the current SDK does not support targeting the requested .NET version, suggesting a newer SDK or lower target. Tied to the installed SDK vs the project TFM.
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
The installed SDK is older than the target TFM
The runner's SDK predates the framework version the project targets, so it cannot build it.
A TFM was bumped without updating CI
A project moved to a newer TargetFramework but the CI SDK install was not updated to match.
How to fix it
Install a newer SDK in CI
- Install an SDK at least as new as your highest target framework.
- Pin it via
global.jsonfor reproducibility. - Rebuild.
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'Lower the target framework
- If you cannot upgrade the SDK, set
TargetFrameworkto a version the SDK supports. - Rebuild.
<TargetFramework>net8.0</TargetFramework>How to prevent it
- Keep the CI SDK at least as new as your highest TFM.
- Update the SDK install step whenever you bump a target framework.
- Pin the SDK with
global.jsonso local and CI agree.