Guide: .NET and NuGet

How to update a NuGet package in many repositories

The commands, the Central Package Management files, and what to do when the same package has to move in every repository.

The change nobody sees, in every repository

One package needs a new version. The work is the same in each repository: find the reference, change the version, restore, build, test, commit, review, merge. Then you do it again in the next repository.

It is boring work, and it comes back every week. An upgrade changes nothing the business or the client can see, so it is hard to ask for time, and the active project always wins. The older applications get no time at all. Those are the repositories that get skipped.

The manual way, step by step

1. Find where the package is used. NuGet can list packages for one project or one solution:

dotnet list package --outdated
dotnet list package --include-transitive

From the .NET 10 SDK the same command is written dotnet package list. Add --format json when a script has to read the result. For security fixes, what is a CVE covers dotnet list package --vulnerable and dotnet nuget why.

2. Change the version. With the version in the project file:

dotnet add package Contoso.Utilities --version 2.4.6

From the .NET 10 SDK this is dotnet package add, and dotnet package update Contoso.Utilities@2.4.6 does the same. If the repository uses Central Package Management, the version lives in one file, Directory.Packages.props, and you change one line there:

<PackageVersion Include="Contoso.Utilities" Version="2.4.6" />

3. Prove it.

dotnet restore
dotnet build
dotnet test

4. Commit and push.

5. Get a review and merge. Then go to the next repository and start again at step 1.

Two panels. Left, headed "By hand": repository-1, repository-2 and repository-3, each with its own row of steps. Right, headed "Once": one approved version goes to canary-1 and canary-2, then to the repository group.
The same steps repeated in every repository, and one approved version proven on canary repositories first.

Where the manual way breaks

Central Package Management helps inside one repository. Across repositories, four things go wrong.

  • Central Package Management stops at the repository

    It gives you one place for versions inside a repository. It does not reach the next one, and a VersionOverride on one project beats the central version, so a project can stay behind unseen.

  • Only the nearest Directory.Packages.props counts

    MSBuild imports the first one it finds. A second file lower in the repository has to import its parent by hand, or it stands alone.

  • A transitive package needs a different move

    NuGet advises updating the package closest to your direct reference first. If that does not clear the warning, add the fixed version as a direct reference or use transitive pinning.

  • Nothing shows the whole picture

    dotnet list package reads one project or one solution. No built-in command that reads across repositories was found, so drift stays hidden until someone checks by hand.

Scripts, spreadsheets and dependency bots

Most teams reach for a script or a spreadsheet next. A script that loops over repositories has to know which ones use Central Package Management, which SDK each one needs (dotnet package update needs the .NET 10 SDK) and how to sign in to a private feed. Someone has to keep it working. A spreadsheet only holds what someone typed in.

Dependency bots are the other answer. Renovate's documentation lists a NuGet manager. Dependabot's documentation lists NuGet among its supported package managers, and its groups option bundles updates into fewer pull requests. In the documentation we read, we found no view of one package version across all your repositories, no approval that covers a group of repositories, and no rollout that proves a version on a few repositories first. If a bot already works for you, keep it.

How Smell That Code changes it

Smell That Code works on a repository group: the repositories that share packages.

  1. Group your repositories

    Smell That Code finds every package version across the repository group.

  2. See the security fixes first

    Suggested upgrades start with the security fixes.

  3. Approve once

    A person approves a version for the repository group, or a rule you set approves it.

  4. Prove it on canary repositories

    The version goes to a few repositories first. If build and tests pass there, it counts as proven.

  5. Run stc upgrade

    stc edits the build files and runs restore, build and test. It never commits, pushes or merges. Your pipeline and your review stay yours.

Source code and credentials are never uploaded. What leaves your machine lists exactly what is uploaded.

Side by side
By hand or scriptDependency botSmell That Code
See one package across all repositoriesPer project or solutionNot found in its documentationOne repository group
Approve once for the groupNoNot found in its documentationA person or a rule
Prove on a few repositories firstBy hand, if at allNot found in its documentationCanary repositories

Is this for you?

  • It fits

    Teams with many repositories to keep on the same package versions: software houses with many client repositories, and platform teams with many small services.

  • It does not fit

    A team with one or two repositories. There, the commands above and a good habit are enough. It also does not fit a team that wants a tool to commit and merge for them, because stc never does.

Questions

How do I update a NuGet package in all projects of a solution?

Run dotnet list package --outdated to see what is behind. Change the version in each project, or, with Central Package Management, change one PackageVersion line in Directory.Packages.props. Then run dotnet restore, dotnet build and dotnet test.

How do I update a NuGet package in multiple repositories?

Repeat the steps in each repository: find, change, prove, commit, review. No built-in command that works across repositories was found. A repository group in Smell That Code lets you approve a version once for all of them.

How do I find which repositories use a NuGet package version?

dotnet list package reads one project or one solution. Across repositories you need a script, a spreadsheet, or a tool that reads the whole repository group.

What is Central Package Management in NuGet?

One file, Directory.Packages.props, with the MSBuild property ManagePackageVersionsCentrally set to true and one PackageVersion per package. The projects list the package without a version.

How do I fix a vulnerable transitive NuGet package?

Update the package closest to your direct reference first. If that does not clear the warning, add the fixed version as a direct reference, or use transitive pinning with CentralPackageTransitivePinningEnabled. What is a CVE shows how to find the path.

Does Smell That Code commit or push my changes?

No. stc upgrade edits your build files and runs restore, build and test. You commit, push and merge.

Find the page for your situation

Smell That Code fits several kinds of teams. Pick the one that sounds like yours.

  • A vulnerability report with a deadline

    You own many .NET repositories, managers read a report of open vulnerabilities, and your team has days to fix each one.

    For teams with a vulnerability KPI
  • Shared packages across many services

    You look after the packages, templates and pipelines that many .NET services use.

    For platform teams
  • Many client projects

    You keep the repositories of many clients up to date, including old projects nobody has opened for months.

    For software houses

Join the waitlist

Smell That Code is not open to everyone yet. Join the waitlist and be the first to try it. A free tier lets you try it on your own repositories.