Problem
When attempting to build a project targeting .NET 9, the build fails with the error: 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. This occurs despite the .NET 9 SDK being installed on the agent.
Cause
The issue arises because .NET 8 is set as the default SDK on JetBrains-hosted agents. A global.json file in the agent's root directory may also point to a previous .NET version.
Resolution
-
Verify Installed .NET SDKs: Execute the following command on the TeamCity agent to list all installed .NET SDK versions:
dotnet --list-sdks -
Switch to .NET 9 (Simplest Method): To automatically use the latest installed version of .NET 9, remove the existing
global.jsonfile:sudo rm /global.json -
Specify a Specific .NET Version Using global.json: To explicitly specify a particular .NET SDK version, create a
global.jsonfile in the project directory or in a higher-level directory. You can either create this file manually or use thedotnetcommand:Manually create the file:
echo '{"sdk":{"version": "9.0.304"}}' > global.jsonUsing a command to create the file:
dotnet new globaljson --sdk-version 9.0.304 -
Switch to the Latest Available 9.x Version: Navigate to the project directory and execute the following command to identify and activate the latest installed .NET 9.x SDK version:
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"
These steps ensure that the TeamCity agent uses the correct version of .NET SDK for the build.
Comments
0 comments
Please sign in to leave a comment.