Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.