Update a NuGet Package Across Multiple Projects in .NET Core
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:
- checks out the file
- goes to the project folder
- updates the package using the Add Package command (it will install the package if the .csproj has the package name in a different context)
- goes back to continue the search
