# IT:AD:NuGet:HowTo:Update Packages in the Solution # * [[../|(UP)]] {{indexmenu>.#2|nsort tsort}} * See: * [[IT/AD/Elmah/]] 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. * Add references to assemblies contained in the package * Add references to framework assemblies in the GAC * Add content files to an app (e.g. JavaScript files, code files, …) * Add assembly binding redirects to deal with version incompatibilities * Perform config transformations, typically to add settings related to the package * Bring in tools that can then be run from Package Manager Console * Run PowerShell scripts which can do arbitrary things by automating the DTE object model >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](https://gist.github.com/747529) * http://blog.davidebbo.com/2011/05/thoughts-on-installing-and-updating.html