Skip to content
BETAGuardrails are in beta. The library, the configuration format and the CLI command can still change.

Guardrails / dotnet

Package references carry a version

dotnet/dependencies-versioned@v1

Every PackageReference names a version itself or takes one from a central PackageVersion.

Iddotnet/dependencies-versioned
Versionv1
Categorydotnet
Default severityerror
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectsdotnet

Collectors

This guardrail gathers nothing itself. It depends on the collectors below, which the CLI runs once per build before any check, and reads what they found out of GUARDRAIL_FACTS. A collector that collects nothing skips this guardrail rather than failing it.

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, passed straight through. Configuring one in buildnote.json changes what is collected, and two guardrails configured the same way share the one collection.

Configuration

json
{
  "guardrails": {
      "failOn": "error",
      "comment": true,
      "checks": [
          {
              "use": "dotnet/dependencies-versioned@v1",
              "severity": "error",
              "with": {
                  "projectDir": "."
              },
              "exemptions": []
          }
      ]
  }
}

Inputs

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

How to fix

Give the reference a version, or a central PackageVersion for it to take one from:

xml
<PackageReference Include="Serilog" Version="4.0.0" />
xml
<PackageVersion Include="Serilog" Version="4.0.0" />

A PackageReference with neither its own version nor a central one restores whatever NuGet picks for it, so the package the build compiled against is chosen at restore time rather than in the commit.

More in dotnet

  • dotnet/central-package-management. One Directory.Packages.props decides the version of every package, rather than each project file deciding its own.
  • dotnet/sdk-pinned. global.json names the SDK the build uses and holds it there, rather than letting a newer one on the runner take over.
  • dotnet/target-framework-floor. Every net<major>.<minor> framework a project targets is no older than the configured floor.

All 4 dotnet guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412