2

I am going through the book "ASP.NET MVC Using C#". After running the book's first example project and finding out it did not work, and about 30 minutes of my coworkers helping me figure it out, we learned the Nuget packages were outdated. Right click references, and update the packages, and it works fine. Takes about a minute. But the thing is, there are about 200 example projects; manually attending to them all would be incredibly tedious and time-consuming.

This leads me ask: Is there a way in Visual Studio to add a package to all solutions, or all future solutions, or anything of that nature? Or, is it possible to update the packages for ALL of Visual Studio?

This is NOT asking for 3rd party tool recommendations or any other off-site resource. Furthermore, there are already 2 answers, neither of which are tool recommendations.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Matt Culb
  • 31
  • 1
  • 4

2 Answers2

1

Add all the projects to a solution. Then right-click on the Solution node in Visual Studio's Solution Explorer and select "Manage NuGet packages for Solution". The NuGet Package Manager will open. On the Updates tab you can update each package for all the projects with just a few clicks; the Consolidate tab shows you where packages with distinct version numbers are used by different projects and you can also update packages from there:

enter image description here

You can also install a new package to all projects through the Browse tab on this window. It's a great tool.


See also:

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
  • Is it possible for me to add over a hundred projects to one single solution? – Matt Culb Feb 14 '18 at 16:32
  • 1
    [I don't see why not](https://stackoverflow.com/a/963555/397817), but it would take a lot of clicking to add them all - unless you can write a script to create the .sln for you. How many .sln files are there, by comparison? I don't have VS handy but I think you may be able to add existing solutions into a .sln? – Stephen Kennedy Feb 14 '18 at 16:36
  • There are 12 chapters, each with 3-10 examples containing a solution. Some of those examples contain 1-4 steps, each one of those containing a solution. Just clicking through the directories I am guessing around 100 solutions, could be more or less. – Matt Culb Feb 14 '18 at 16:41
  • 1
    Have a look at [this](https://stackoverflow.com/q/1891035/397817) There's multiple suggestions here on how to easily add tons of projects to an sln :) [One answer](https://stackoverflow.com/a/46393399/397817) offers a free tool, but I've not tried it. – Stephen Kennedy Feb 14 '18 at 16:45
  • I have found that none of these solutions really help save much time or are even that easy or practical to pull off. The projects need to be saved in a specific directory. The only reasonable thing to do is just update the packages manually every time I open up one of the examples, sadly. Thank you for all of your help though! – Matt Culb Feb 15 '18 at 19:59
0

Another approach is to use your text editor or shell to find and replace the package references which you want to update in bulk.

For projects created in Visual Studio 2015 and earlier, and projects created with certain templates in Visual Studio 2017, there are two files which have to be changed for each project: the *.csproj project file (example) and the packages.config Nuget file (example).

Readers fortunate enough to be working with 'new format' csproj files created by Visual Studio 2017 will find it a lot easier to make changes like this with a text editor because the package reference is neatly constrained to PackageReference nodes in the .csproj file only.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
  • Thank you for all of your help, I'll try these solutions out when I get the time, and report back with what I find. – Matt Culb Feb 14 '18 at 18:01
  • No problem. If you go with either solution you can click to accept it. If you find some other totally different way which might benefit other readers then it's quite ok to post an answer to your own question and accept that. Anyway, good luck. – Stephen Kennedy Feb 14 '18 at 18:04