Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update nuget packages in many solutions at once

Tags:

nuget

I have a repository with a lot of solutions. Sometimes I need to update one package to a newer version. It is way to slow opening each solution and updating via visual studio.

What is the best way to update a single package to a newer version for many solutions in the same git repository all at once?

like image 540
Jakob Avatar asked Jul 31 '15 22:07

Jakob


People also ask

How do I refresh all NuGet packages?

Switch to the Browse tab, search for the package name, select it, then select Install). For all packages, delete the package folder, then run nuget install . For a single package, delete the package folder and use nuget install <id> to reinstall the same one.

How do I Update NuGet dependencies?

By Command-line: You can download nuget.exe,and add the path where it exists to Path system environment variables. Then you could simply reference the nuget.exe directly. After that you can use command like nuget update YourSolution. sln in Package Manager Console to update the dependencies for solution.

How do I Update NuGet to latest version?

Right-click the Packages folder in the project, and select Update. This will update the NuGet package to the latest version. You can double-click the Add packages and choose the specific version.


2 Answers

What I did is just find replace the version numbers needed to be updated with the help of sublime. This solution is risky but the only one I have found.

  • I updated the references in the solution files and the version numbers in the package.config files.

For example: EntityFramework version 4.3.0 to version 6.0.0

  1. Update the solution files Find with regex: <Reference Include="EntityFramework((?s).*?)</Reference>
    Where: *.csproj
    Replace with: <Reference Include=\"EntityFramework, Version=6.0.0.0\">\n\t\t<HintPath>$\(SolutionDir\)\\packages\\EntityFramework.6.0.0\\lib\\net45\\EntityFramework.dll<\/HintPath>\n\t<\/Reference>

  2. Update the package files Find with regex: <package id="EntityFramework" version="((?s).*?)" targetFramework="net45" />
    Where: packages.config
    Replace with: <package id="EntityFramework" version="6.0.0" targetFramework="net45" />

like image 152
Jakob Avatar answered Oct 30 '22 17:10

Jakob


NuGet comes with different frontends, one being a command line application (Download) that also allows to update package references. Thomas Ardal provided a nice PowerShell script that can be used to update packages across multiple solutions:

param(
    [Parameter(Mandatory=$true)]
    [string]$packageId
)

Get-ChildItem *.sln -recurse | %{.\\nuget.exe restore $_.fullname}

Get-ChildItem packages.config -Recurse `
  | Where-Object {$_ | Select-String -Pattern $packageId} `
  | %{.\\nuget.exe update -Id $packageId $_.FullName}

Please note that this method does not support to control the dependency behavior and will update dependencies to their highest available version.

like image 37
CodeFox Avatar answered Oct 30 '22 17:10

CodeFox