Preventing a NuGet update from silently bringing in a new licence: Central Package Management, pinned majors and lock files, Dependabot ignore rules, CI licence allow-lists (dependency-review-action, nuget-license), and treating test packages like production dependencies.
A NuGet package version is immutable, so a licence can only change when you take a new version. The job is to control which versions get in:
Directory.Packages.props) puts every version in one file that gets reviewed, and lock files pin transitive packages too.ignore rules for major versions of sensitive packages. Majors are where licences change: FluentAssertions 8 moved to a paid commercial licence in January 2025.allow-licenses, or the nuget-license tool, against an allow-list. It also fails on unknown licences.Test and build packages get the same review as production ones. The trade-off is some friction on every upgrade, in exchange for never finding a commercial licence during an audit.
"First, the mechanism. On nuget.org a published version never changes, so a licence change always arrives with a new version. FluentAssertions is the well-known case: version 7 was Apache 2.0, and version 8, released in January 2025, moved to the Xceed commercial licence. A team that let Dependabot auto-merge the major update suddenly needed a paid licence for commercial use. So 'silently' really means 'a version bump nobody read'.
I stop that at three points. Where versions are declared: Central Package Management, so every version lives in
Directory.Packages.props. A change there is a one-line diff that's easy to spot in a pull request. I also turn on lock files, so transitive packages can't drift either. Where updates come from: Dependabot is grouped and allowed to raise minor and patch updates, but hasignorerules for major versions of packages we've flagged, and nothing auto-merges majors. In CI: a licence gate. On GitHub that'sdependency-review-actionwith an allow-list such as MIT, Apache-2.0 and the BSD licences. Elsewhere I use thenuget-licensetool against a JSON allow-list. Unknown or non-SPDX licences fail the build until someone looks.The mistake I see is thinking test packages don't matter because they don't ship. They run on every developer laptop and build agent, they're part of the supply chain, and commercial licences usually still apply. The rule I use: anything restored is a dependency, whatever folder it's in."
| Control | What it stops | How |
|---|---|---|
| Central Package Management | Versions scattered across 40 .csproj files |
ManagePackageVersionsCentrally + Directory.Packages.props |
| Transitive pinning and lock files | A transitive package drifting to a new major | CentralPackageTransitivePinningEnabled, RestorePackagesWithLockFile, dotnet restore --locked-mode in CI |
| Dependabot ignore for majors | Auto-raised major updates on flagged packages | ignore with update-types: ["version-update:semver-major"] |
| Licence gate in CI | A disallowed or unknown licence merging | dependency-review-action allow-licenses, or nuget-license -a allowed.json |
| CODEOWNERS on the props file | Package changes merging without the right reviewer | /Directory.Packages.props @platform-team |
| Licence metadata | Scanner result |
|---|---|
SPDX expression (<license type="expression">MIT</license>) |
Reliable |
| Licence file in the package | Usually "unknown": needs a human |
Deprecated licenseUrl only |
Unreliable: the URL's content can change |
A solution with around 180 direct and transitive packages can run a licence gate in under a minute per pull request. In practice it fires a few times a year, usually on a major upgrade or a new transitive dependency. Each one costs a five-minute review, compared with a procurement problem found months later.
Checks whether the candidate understands dependency licences as part of supply-chain risk and knows the practical .NET controls.
Green flags
Red flags
Maintainers relicense to fund the work (FluentAssertions with Xceed in 2025), to stop cloud providers reselling them, or after an acquisition. On NuGet the old versions keep their old licence, because packages are immutable. That's what makes the problem controllable: you only need to govern version changes.
Dependabot / developer ──▶ PR changes Directory.Packages.props
│
┌─────────────┼──────────────┐
▼ ▼ ▼
restore --locked-mode licence gate CODEOWNERS review
(lock file updated?) (allow-list) (human reads it)
└─────────────┼──────────────┘
▼
merge
With <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> in Directory.Packages.props, project files carry <PackageReference Include="xunit.v3" /> with no version, and the props file holds <PackageVersion Include="xunit.v3" Version="..." />. Turning on CentralPackageTransitivePinningEnabled lets you pin a transitive package by listing it. NuGet then treats it as if you had referenced it directly.
RestorePackagesWithLockFile writes packages.lock.json per project with the exact resolved version of every package, direct and transitive. In CI, dotnet restore --locked-mode fails if restore would produce anything different. Lock file changes show up in the pull request, so a new transitive dependency is visible.
allow-licenses or deny-licenses. It reads licence data from package metadata, so it sees what the package declared.Since .NET 8, restore runs NuGetAudit and warns about packages with known vulnerabilities (CVEs from the GitHub Advisory Database). It says nothing about licences. You need both, and both feed into the wider supply-chain controls that ACSC guidance asks for.
dependency-review-action with an allow-list of MIT and Apache-2.0, then open a pull request that adds a package with another licence.nuget-license on your solution and find any package with an "unknown" licence.dotnet list package --include-transitive and count how many packages you never chose directly.The pieces that work together: central versions with lock files, Dependabot rules, and a CI licence gate.
<!-- Directory.Packages.props: every version in one reviewed file -->
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="xunit.v3" Version="3.2.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<!-- Shouldly (BSD-3-Clause) chosen instead of FluentAssertions 8 (commercial). -->
<PackageVersion Include="Shouldly" Version="4.3.0" />
</ItemGroup>
</Project>
<!-- Directory.Build.props: lock files for every project -->
<Project>
<PropertyGroup>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
</Project>
# .github/dependabot.yml: minors and patches grouped, majors on flagged packages ignored
version: 2
updates:
- package-ecosystem: nuget
directory: /
schedule:
interval: weekly
groups:
minor-and-patch:
update-types: [minor, patch]
ignore:
- dependency-name: "Shouldly"
update-types: ["version-update:semver-major"]
- dependency-name: "NSubstitute"
update-types: ["version-update:semver-major"]
# .github/workflows/pr.yml: fail the PR on a disallowed licence
name: pr
on: pull_request
permissions:
contents: read
jobs:
dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- run: dotnet restore --locked-mode # transitive drift fails here
- uses: actions/dependency-review-action@v4
with:
allow-licenses: MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause
fail-on-severity: high # vulnerabilities too
The version numbers are examples. Use whatever your solution has approved.
licenseUrl metadata are where unusual terms hide. Instead: Fail on unknown and keep an allow-list of reviewed exceptions..csproj. Why it is wrong: A change hides among many files and versions drift apart. Instead: Use Central Package Management with CODEOWNERS on the props file.This is supply-chain governance, and the cheapest point to apply it is the pull request. Once a package has spread through 30 projects and a year of code, replacing it costs weeks. I agree an allow-list with whoever owns legal risk once, put it in the repository, and let CI enforce it. Humans only see the exceptions. I'd also write an ADR for any library we pick partly because of its licence (Shouldly or AwesomeAssertions over FluentAssertions 8, NSubstitute over Moq after SponsorLink), so the next person knows why.
I measure it by counting licence-gate failures and how long they take to resolve. A few a year, each closed within a day, means the process works without slowing the team.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| dependency-review-action | Code on GitHub, PR-based flow | Free for public repos; private repos need GitHub Advanced Security | Azure DevOps-only pipelines |
| nuget-license tool in the pipeline | Any CI, including Azure DevOps | A tool step and an allow-list file | You already have an SCA platform |
| Commercial SCA (Snyk, Mend, Black Duck) | Many repos, legal reporting, policy across languages | Licence fees, onboarding | One small solution |
| Manual review only | Tiny project with a handful of packages | Human time, easy to skip | Anything with Dependabot or many contributors |
Last updated 23 Nov 2026.