Skip to content

Instantly share code, notes, and snippets.

@staxmanade
Created June 6, 2011 04:09
Show Gist options
  • Save staxmanade/1009729 to your computer and use it in GitHub Desktop.
Save staxmanade/1009729 to your computer and use it in GitHub Desktop.
Powershell function that returns the last version of a NuGet package
function Get-Last-NuGet-Version($nuGetPackageId) {
$feeedUrl = "http://packages.nuget.org/v1/FeedService.svc/Packages()?`$filter=Id%20eq%20'$nuGetPackageId'"
$webClient = new-object System.Net.WebClient
$queryResults = [xml]($webClient.DownloadString($feeedUrl))
$version = $queryResults.feed.entry | %{ $_.properties.version } | sort-object | select -last 1
if(!$version){
$version = "0.0"
}
$version
}
function Increment-Version($version){
$parts = $version.split('.')
for($i = $parts.length-1; $i -ge 0; $i--){
$x = ([int]$parts[$i]) + 1
if($i -ne 0) {
# Don't roll the previous minor or ref past 10
if($x -eq 10) {
$parts[$i] = "0"
continue
}
}
$parts[$i] = $x.ToString()
break;
}
[System.String]::Join(".", $parts)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment