Skip to content

Guardrails / dotnet

Package versions are managed centrally ​

dotnet/central-package-management@v1

A single Directory.Packages.props sets the version of every package, instead of each project file setting its own.

Iddotnet/central-package-management
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/central-package-management@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 ​

Turn on central package management in a Directory.Packages.props next to the solution, and remove the Version attributes from the project files:

xml
<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="Serilog" Version="4.0.0" />
  </ItemGroup>
</Project>

When every project file sets its own versions, two projects in the same solution can restore different versions of the same package, and an upgrade only lands in the project files someone remembered to edit.

More in dotnet ​

All 4 dotnet guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412