Skip to content

Instantly share code, notes, and snippets.

@jimbuck
Created October 4, 2017 00:05
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 jimbuck/27a9d43822c1dfa4a2962656c4fe2f01 to your computer and use it in GitHub Desktop.
Save jimbuck/27a9d43822c1dfa4a2962656c4fe2f01 to your computer and use it in GitHub Desktop.
Bump version of csproj
param(
[string]$csproj = $(throw "-csproj is required."),
[ValidateSet('major', 'minor', 'patch')][string]$part = "patch"
)
Function BumpVersion([string]$csprojPath, [int]$majorInc, [int]$minorInc, [int]$patchInc) {
[xml]$xml = (Get-Content $csprojPath)
$buildInfo = $xml.Project.PropertyGroup | Where-Object {$_.Label -eq 'BuildInfo'}
#split product version in SemVer language
$versions = ($buildInfo.Version + "").Split('.')
if ($versions.Length -eq 3) {
$major = ([int]$versions[0]) + $majorInc
$minor = ([int]$versions[1]) + $minorInc
$patch = ([int]$versions[2]) + $patchInc
}
else {
throw "Failed to parse version number!"
}
$buildInfo.Version = "$major.$minor.$patch"
$xml.Save($csprojPath)
Write-Host "BUMPED: " $buildInfo.Version
}
switch ($part) {
"major" {BumpVersion $csproj 1 0 0; break}
"minor" {BumpVersion $csproj 0 1 0; break}
"patch" {BumpVersion $csproj 0 0 1; break}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment