Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update all NuGet packages at once with the dotnet CLI?

I'm trying to update all NuGet packages for a solution in VS Code (using Mac). Is there a way to achieve that in VS code or for a specific project.json file? At the moment I'm going one by one but I would have thought there is either an extension or a feature that does that for you?

like image 391
Carlos Torrecillas Avatar asked Dec 10 '16 21:12

Carlos Torrecillas


People also ask

Which command is used to install NuGet packages using dotnet CLI?

NuGet installs the latest version of the package when you use the dotnet add package command unless you specify the package version ( -v switch).


2 Answers

For Update all packages in all projects nuget package manager gui extension can do it with one click.

How it works

  1. Open your project workspace in VSCode
  2. Open the Command Palette (Ctrl+Shift+P)
  3. Select > Nuget Package Manager GUI
  4. Click Load Package Versions
  5. Click Update All Packages

test

like image 142
Ali.Asadi Avatar answered Sep 21 '22 06:09

Ali.Asadi


Based on Jon Canning's powershell solution. I fixed a small bug where only the first dependency was being updated and not all the dependencies for the project file.

$regex = 'PackageReference Include="([^"]*)" Version="([^"]*)"'  ForEach ($file in get-childitem . -recurse | where {$_.extension -like "*proj"}) {     $packages = Get-Content $file.FullName |         select-string -pattern $regex -AllMatches |          ForEach-Object {$_.Matches} |          ForEach-Object {$_.Groups[1].Value.ToString()}|          sort -Unique          ForEach ($package in $packages)     {         write-host "Update $file package :$package"  -foreground 'magenta'         $fullName = $file.FullName         iex "dotnet add $fullName package $package"     } } 
like image 41
Rolf Wessels Avatar answered Sep 25 '22 06:09

Rolf Wessels