📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you stop a package update from silently changing the licence of a dependency in your solution?

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.

Intermediate Theory Intermediate central-package-management dependabot licensing nuget supply-chain-security testing

🎯 Key points

  • NuGet packages are immutable, so a licence can only change with a new version: control which versions get in
  • Central Package Management (Directory.Packages.props) puts every version in one reviewed file
  • Lock files (RestorePackagesWithLockFile + --locked-mode) pin transitive versions too
  • Dependabot ignore rules for semver-major on sensitive packages; majors are where licences change (FluentAssertions 8, 2025)
  • CI licence gate: dependency-review-action allow-licenses, or the nuget-license tool against an allow-list
  • Fail on unknown or non-SPDX licences (licence files, deprecated licenseUrl)
  • Test, analyser and build packages count too: they run on developer machines and build agents
  • NuGetAudit checks vulnerabilities, not licences

⏱ 30-second answer

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:

  • Central Package Management (Directory.Packages.props) puts every version in one file that gets reviewed, and lock files pin transitive packages too.
  • Dependabot ignore rules for major versions of sensitive packages. Majors are where licences change: FluentAssertions 8 moved to a paid commercial licence in January 2025.
  • A CI licence gate such as GitHub's dependency-review-action with 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.

🗣 Full answer (senior)

How I would answer this in an interview

"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 has ignore rules for major versions of packages we've flagged, and nothing auto-merges majors. In CI: a licence gate. On GitHub that's dependency-review-action with an allow-list such as MIT, Apache-2.0 and the BSD licences. Elsewhere I use the nuget-license tool 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."


The controls

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

What the scanners can and can't see

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

Production example

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.

🔍 What the interviewer is checking

Checks whether the candidate understands dependency licences as part of supply-chain risk and knows the practical .NET controls.

Green flags

  • Knows NuGet versions are immutable, so the risk is in upgrades.
  • Names Central Package Management, lock files and Dependabot ignore rules for majors.
  • Describes a CI allow-list gate that fails on unknown licences.
  • Gives FluentAssertions 8 as a real example and includes test packages in scope.

Red flags

  • "Test packages don't ship, so licences don't matter."
  • Confuses NuGetAudit or vulnerability scanning with licence checking.
  • Auto-merges all dependency updates.

📚 Learn in depth

1. Why licences change at all

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

2. Central Package Management

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.

3. Lock files

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.

4. Licence scanning

  • GitHub dependency review compares the dependency graph before and after the pull request and checks each added or changed package against allow-licenses or deny-licenses. It reads licence data from package metadata, so it sees what the package declared.
  • nuget-license (a .NET global tool) walks the solution's packages, including transitive ones, and checks them against an allow-list file. It can also export a report for the legal team.
  • Neither tool is a lawyer. Dual licences, licence files and "free for non-commercial use" terms need a human.

5. NuGetAudit is a different thing

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.

Try it yourself

  1. Convert a small solution to Central Package Management and enable lock files. Then bump one package and read the lock file diff.
  2. Add 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.
  3. Run nuget-license on your solution and find any package with an "unknown" licence.
  4. Write a Dependabot config that groups minor and patch updates and ignores majors for two named packages.
  5. Run dotnet list package --include-transitive and count how many packages you never chose directly.

💻 Code

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.

⚠ Common mistakes

  • Mistake: Auto-merging every Dependabot pull request, majors included. Why it is wrong: Majors are exactly where licences change, as FluentAssertions 8 did in 2025. Instead: Auto-merge patches at most, and send majors to human review with ignore rules for flagged packages.
  • Mistake: Treating test packages as out of scope. Why it is wrong: They're restored on every developer machine and build agent, and commercial licences still apply to them. Instead: Scan and review every restored package.
  • Mistake: Only checking direct dependencies. Why it is wrong: Most packages in a solution are transitive, and they can change under a minor bump of something you did choose. Instead: Use lock files and scan the full graph.
  • Mistake: Letting unknown licences pass. Why it is wrong: Licence files and old licenseUrl metadata are where unusual terms hide. Instead: Fail on unknown and keep an allow-list of reviewed exceptions.
  • Mistake: Relying on NuGetAudit. Why it is wrong: It reports vulnerabilities, not licences. Instead: Run a licence gate alongside it.
  • Mistake: Writing version numbers in each .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.

🏛 Senior insight: trade-offs

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

↩ Usually asked after

More in .NET Testing Tools

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me