Skip to content

Instantly share code, notes, and snippets.

@oscarkuo
Created December 15, 2016 01:45
Show Gist options
  • Save oscarkuo/34d2038174514081b772806cadad03d3 to your computer and use it in GitHub Desktop.
Save oscarkuo/34d2038174514081b772806cadad03d3 to your computer and use it in GitHub Desktop.
# 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