Update a NuGet Package Across Multiple Projects in .NET Core

Abdullah Alaqeel
Nov 8 · 1 min read

I recently was assigned the task of updating a NuGet package in 55 projects. Doing it manually would have taken me an eternity.

Luckily, my boss sent me this tutorial by Thomas Ardal. However, it does not work on .NET Core because the framework does not use package.config files anymore. Instead, it stores the NuGet configurations in {projectName}.csproj

After some modifications, we settled into this:

The code takes in the package ID as input, iterates through all the .csproj files within the specified source directory, checks if each file has the package ID within it.

Then for each file that matches the criteria:

  1. checks out the file
  2. goes to the project folder
  3. updates the package using the Add Package command (it will install the package if the .csproj has the package name in a different context)
  4. goes back to continue the search
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade