Symptoms
Affected versions: TeamCity Cloud (build 186049)
When the build targeting .NET 9 is run on the JetBrains-hosted build agent, it fails with the following error.
/usr/share/dotnet/sdk/8.0.408/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(166,5): 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. Download the .NET SDK from https://aka.ms/dotnet/download
Cause
.NET 9 is now configured not to be the default SDK, as we have a policy of enforcing an LTS version (if applicable) of the tools we have installed according to their release lifecycle documentation. When we rolled out the upgrade containing the newer version by default, it was breaking builds for quite a number of customers, so we decided to roll back and enforce .NET 8 as the default.
Resolution
If the current .NET SDK version (8.x) does not meet your requirements, you can switch .NET to use another installed version.
- Get a list of installed .NET SDK versions:
dotnet --list-sdks - Switching to .NET v9 (the simplest method):
The easiest way to switch to .NET v9 is to remove the
global.jsonfile located in the root directory:sudo rm /global.jsonIn this case, the latest installed version will be used. - Switching to a specific installed version:
To switch to any installed version, create a
global.jsonfile in the project directory. Manually:echo '{"sdk":{"version": "X.Y.Z"}}' > global.jsonOr using the command:dotnet new globaljson --sdk-version X.Y.Z - Switch to the latest installed 9.x version with one command:
To switch to the latest available 9.x version, navigate to the project directory and run the command that detects the latest 9.x .NET SDK version and creates
global.json:major_version=9; dotnet_version=$(dotnet --list-sdks 2>/dev/null | awk -v major="$major_version" '$1 ~ "^"major"\\."' | sort -V | tail -n1); [ -n "$dotnet_version" ] && { dotnet new globaljson --sdk-version "$dotnet_version" >/dev/null 2>&1; echo "Using .NET SDK version: $dotnet_version"; } || echo "No matching .NET SDK version found for major version $major_version"
Comments
0 comments
Please sign in to leave a comment.