Table of Contents

.NET SDK pinning (two SDKs on the agent)



The problem: two SDKs on the agent

The TeamCity agents now have both .NET 8 and .NET 10 SDKs installed. When no global.json is present, the dotnet CLI selects the highest installed SDK (.NET 10). MIB 6.0 targets .NET 8, and building it with .NET 10 fails — typically with CS0023 and the build exiting with code 155.

Key rule about resolution: dotnet looks for global.json starting from the current working directory and walking up the parent directories — never into subfolders. So the file must sit at, or above, the directory where the dotnet command runs.



How the mainline 6.0 build pins it

The releases/6.0 branch carries a global.json at the repository root (added in MEDIAIBOX-12053):

{
  "sdk": {
    "version": "8.0.100",
    "rollForward": "latestFeature"
  }
}

rollForward: latestFeature keeps selection inside the 8.0.x feature band and never jumps to .NET 10. In the aggregate build, each dotnet pack step runs with Working directory = <repo>, so it finds that repository's committed global.json.



The problem with old tags (Fix builds)

Tags cut before MEDIAIBOX-12053 do not have a global.json. A release branch/tag going to production must not be modified, so we cannot simply commit the file onto the fix branch.

Note that the Required SDK field of the .NET runner does not solve this — it only requires that the agent has that SDK version (an agent-capability filter); it does not force the dotnet CLI to use that version. Only global.json (or the CLI on the PATH) drives SDK selection.



The fix: write an ephemeral global.json at build time

Add a Command Line build step, placed before the NuGet - Package … steps, that writes a global.json into the checkout root (the parent of every repository folder). This pins .NET 8 for every pack step without touching any branch:

echo '{ "sdk": { "version": "8.0.100", "rollForward": "latestFeature" } }' > "%teamcity.build.checkoutDir%/global.json"
cat "%teamcity.build.checkoutDir%/global.json"

Why the checkout root works: the aggregate build checks each repo out into Projects/<repo>, and the pack steps run with Working directory = <repo>. Since the checkout root is an ancestor of every <repo> folder, dotnet walks up from the repo and finds the single global.json there — one file covers all pack steps. The cat prints it to the log so you can confirm the pin was applied.



If a build still fails on SDK selection even with a global.json, the agent's dotnet CLI may only see .NET 10 (for example, a DotNetCLI_Path pointing to a location that contains only the .NET 10 SDK). Check on the agent:

dotnet --list-sdks

It must list an 8.0.x entry. If it does not, install the .NET 8 SDK on the agent — see Agent reinstallation.