Table of Contents

IT:AD:NuGet:HowTo:Update Packages in the Solution

Summary

As they say in the advertisement, having Nuget manage your Packages and keep them up to date is practically seamless and automatic.

In reality…it's not.

But Nuget remains so much better than the older options that one has to grit one's teeth and bear with it.

Background

Process

Via Package Manager Console

Use the powershell commands to do the updates:

Update all packages in solutiuons

Update-Package

Update a single package

Update-Package Elmah

Update a single project

Update-Package -Project MyProject

Update a single project, with version.

install-package Nab.wdms.PM.M01.Infrastructure.Data.Seeding XAct.Data.Db.EF -Version 0.0.650
Watch out: it might be versioned...but it refers to is not...so XAct.Core (higher version) might get called in...

Background

According to: http://blog.davidebbo.com/2011/05/thoughts-on-installing-and-updating.html what happens is more than just a copy/update of the project files.

It explains why the Package Manager Console has a $dte reference -- it would be very hard to do the above from outside Visual Studio.

Custom scripts

Warning:markdown munge:

###########################################################
#
# Script to upgrade all NuGet packages in solution to last version
#
# USAGE
# Place this file (Upgrade-Package.ps1) to your solution folder. 
# From Package Manager Console execute
#
# .\Upgrade-Package.ps1 -PackageID:Castle.Core
#
# Do not hestitate to contact me at any time
# mike@chaliy.name, http://twitter.com/chaliy
#
# Update to NuGet 1.1 is done by JasonGrundy, see comments bellow
#
##########################################################

param($PackageID)

$packageManager = $host.PrivateData.packageManagerFactory.CreatePackageManager()

foreach ($project in Get-Project -all) {
$fileSystem = New-Object NuGet.PhysicalFileSystem($project.Properties.Item("FullPath").Value)   
$repo = New-Object NuGet.PackageReferenceRepository($fileSystem, $packageManager.LocalRepository)

foreach ($package in $repo.GetPackages() | ? {$_.Id -eq $PackageID}) {
  Update-Package $package.Id -Project:$project.Name 
}
}

Resources

* https://gist.github.com/747529 * http://blog.davidebbo.com/2011/05/thoughts-on-installing-and-updating.html