Created
October 4, 2017 00:05
-
-
Save jimbuck/27a9d43822c1dfa4a2962656c4fe2f01 to your computer and use it in GitHub Desktop.
Bump version of csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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