Created
December 15, 2016 01:45
-
-
Save oscarkuo/34d2038174514081b772806cadad03d3 to your computer and use it in GitHub Desktop.
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
# source http://stackoverflow.com/questions/36200323/get-and-replace-assemblyversion-from-assemblyinfo-cs | |
function Update-Version($path, $pattern, $template, $newVersion) | |
{ | |
(Get-Content $path) | ForEach-Object{ | |
if($_ -match $pattern){ | |
$fileVersion = [version]$matches[1] | |
$now = Get-Date | |
$newVersion = "{0}.{1}.{2}.{3}" -f $now.Year, $now.ToString("MMdd"), $now.ToString("HHmm"), ($fileVersion.Revision+1) | |
$template -f $newVersion | |
} else { | |
$_ | |
} | |
} | Set-Content $path | |
} | |
$p = "MyProject\Properties\AssemblyInfo.cs" | |
Update-Version $p '\[assembly: AssemblyVersion\("(.*)"\)\]' '[assembly: AssemblyVersion("{0}")]' | |
Update-Version $p '\[assembly: AssemblyFileVersion\("(.*)"\)\]' '[assembly: AssemblyFileVersion("{0}")]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment