-
-
Save chaliy/747529 to your computer and use it in GitHub Desktop.
########################################################### | |
# | |
# 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 | |
# [email protected], 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 | |
} | |
} |
The complete script for NuGet 1.1 would be:
param($PackageID)
$packageManager = $host.PrivateData.packageManagerFactory.CreatePackageManager()
foreach ($project in Get-Project) {
$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
}
}
Which would be invoked using:
Get-Package foo –Updates | Get-Unique | ForEach-Object { .\Upgrade-Package.ps1 $_.Id }
davidfowl & JasonGrundy thanks for pointing out, script has been updated with you changes.
This script will update only default project in solution. You need to specify "Get-Project -all" in foreach loop.
Hm, didn't tested last version, let me fix this.
can't seem to get this working ...
When running:
PM> Get-Package -updates
Id Version Description
DataAnnotationsExtensions 0.5.0.0 Validation attributes that can be used in any .NET 4.0 project to supplement the existing Data Annotations attributes. ...
EFCodeFirst 1.0 Legacy package, Code First is now included in the 'EntityFramework' package.
jQuery 1.5.2 jQuery is a new kind of JavaScript Library....
jQuery.vsdoc 1.5.2 Includes vsdoc files for jQuery 1.5.2 that provide IntelliSense in Visual Studio 2010. For best experience get the JScript Edi...
StructureMap-MVC3 1.0.6 Adds the latest version of structuremap and configures it as the default Dependency Resolver.
WebActivator 1.4 A NuGet package that allows other packages to execute some startup code in web apps
So there are stuff to update ...
Running:
PM> ./Upgrade-Package.ps1
PM>
Nothing happens
I need to run:
PM> ./Upgrade-Package.ps1 jQuery.vsdoc
'jQuery 1.5.2' already installed.
Successfully installed 'jQuery.vsdoc 1.5.2'.
Successfully removed 'jQuery.vsdoc 1.5.1' from TravianBox.Web.
Successfully uninstalled 'jQuery.vsdoc 1.5.1'.
Successfully removed 'jQuery 1.5.1' from TravianBox.Web.
Successfully uninstalled 'jQuery 1.5.1'.
Successfully added 'jQuery 1.5.2' to TravianBox.Web.
Successfully added 'jQuery.vsdoc 1.5.2' to TravianBox.Web.
PM>
To actually update any packages ...
Am I doing something wrong here? Shuld it not be possible to update all packages within a solution ?
mvh
Mikael Syska
I have used it with 1.1 ... and well and a few days ago: 1.2 came out of NuGet ... so I dont have any projects atm that needs updating ...
So ... I think I'm getting a little closer to a solution ... of some sort.
When there are still old versions laying around in the packages directory, even though the new version is also there, it keeps telling me that there were updates.
Removed the old version solved that issue.
So now when running:
PM> Get-Package -updates
No package updates are available from the current package source.
PM>
I love NuGet ... but this is a odd bug ... maybe because of the nature of T4MVC ?
Or the DataAnnotationsExtensions. Since it was actually the same file with version 0.4.0.0 and 0.5.0.0 ... but the DataAnnotationsExtensions.MVC3 had changed ... Still the version number of the dll's were still 0.4.0.0
I'm no expert in this area ... but could that cause problems maybe ?
This is awesome. I wrote a NuGet package based on this: http://nuget.org/List/Packages/NuGetPackageUpdater
It overrides the default update-package and makes it global.
Mikael, Upgrade-Package.ps1 supports only updating single dependency. Pls note that this script is not official or something else. I just wrote it for my purposes.
ferventcoder, thats nice. And it supports updating all packages, so Mikael can use it.
Also today Haacked posted survey about related stuff coming to next versions of nuget http://haacked.com/archive/2011/04/06/nuget-needs-your-input.aspx .
I just read the first line in the description: "Script to upgrade all NuGet packages in solution to last version" and assumed it updated all packages to there latest version I none argument was given on the line.
Yes, Now I know that for sure and I will be looking at both NuGetPackageUpdater and have allready voted on Haacked's blog.
But still thanks very much for this script since it still helped me.
mvh
In NuGet 1.1 you can use:
$packageManager = $host.PrivateData.packageManagerFactory.CreatePackageManager()