Skip to content

Guardrails / dotnet

.NET SDK is pinned ​

dotnet/sdk-pinned@v1

global.json names the SDK the build uses and holds it there, so a newer SDK on the runner can't take over.

Iddotnet/sdk-pinned
Versionv1
Categorydotnet
Default severitywarning
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectsdotnet

Collectors ​

This guardrail doesn't gather anything itself. It relies on the collectors below, which the CLI runs once per build before any check, and reads what they found from GUARDRAIL_FACTS. If a collector collects nothing, this guardrail is skipped, not failed.

CollectorGathersInputs it is given
dotnetThe .NET build in the project directory: the SDK it pins, every project file and the frameworks each targets, the packages they reference and which of them are pinned or supplied centrally, and the lock files beside them.projectDir

The inputs above are this guardrail's own inputs, passed straight through to the collector. Setting one in buildnote.json changes what is collected, and two guardrails configured the same way share a single collection.

Configuration ​

json
{
  "guardrails": {
      "failOn": "error",
      "checks": [
          {
              "use": "dotnet/sdk-pinned@v1",
              "severity": "warning",
              "with": {
                  "projectDir": "."
              },
              "exemptions": []
          }
      ]
  }
}

Inputs ​

InputDescriptionDefaultEnvironment variable
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR

How to fix ​

Pin the SDK in a global.json at the root of the checkout, and stop it from rolling forward:

json
{
  "sdk": {
    "version": "8.0.204",
    "rollForward": "disable"
  }
}

Any rollForward policy other than disable lets a newer SDK on the runner take over the build, so global.json on its own is not a pin. Without the pin, MSBuild and compiler changes arrive with the runner image instead of with a commit someone reviewed.

More in dotnet ​

All 4 dotnet guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412