Skip to content

Instantly share code, notes, and snippets.

@qbikez
Created February 7, 2016 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qbikez/3c8058dcde33e2643786 to your computer and use it in GitHub Desktop.
Save qbikez/3c8058dcde33e2643786 to your computer and use it in GitHub Desktop.
powershell helper functions for manipulating nuspec
function Get-NuspecVersion($nuspec = $null) {
if ([string]::IsNullOrEmpty($nuspec)) {
$nuspec = Get-ChildItem . -Filter *.nuspec | select -First 1
}
$content = Get-Content $nuspec
$verRegex = "<version>(.*)</version>"
[string]$line = $content | where { $_ -match $verRegex } | select -First 1
$ver = $matches[1]
return $ver
}
function Set-NuspecVersion([string] $version, $nuspec = $null) {
if ($nuspec -eq $null) {
$nuspec = Get-ChildItem . -Filter *.nuspec | select -First 1
}
$content = Get-Content $nuspec
$content2 = $content | foreach {
if ($_ -match "<version>(.*)</version>") {
$_.Replace( $matches[0], "<version>$version</version>")
} else {
$_
}
}
$content2 | Set-Content $nuspec
}
function Incremet-NuspecVersion($nuspec = $null) {
if ($nuspec -eq $null) {
$nuspec = Get-ChildItem . -Filter *.nuspec | select -First 1
}
$ver = Get-NuspecVersion $nuspec
$vernums = $ver.Split('.')
$lastNum = [int]::Parse($vernums[$vernums.Count-1])
$lastNum++
$vernums[$vernums.Count-1] = $lastNum.ToString()
$ver2 = [string]::Join(".", $vernums)
Set-NuspecVersion -version $ver2 -nuspec $nuspec
}
function Incremet-Version($nuspec = $null) {
Incremet-NuspecVersion -nuspec $nuspec
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment