Skip to content

Instantly share code, notes, and snippets.

@rosberglinhares
Created May 13, 2016 03:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rosberglinhares/0a35087b6ba9165ff0df0618ffacbf0a to your computer and use it in GitHub Desktop.
Save rosberglinhares/0a35087b6ba9165ff0df0618ffacbf0a to your computer and use it in GitHub Desktop.
Powershell script to increment assembly version
Param (
[Parameter(Mandatory=$true)]
[string] $AssemblyInfoPath
)
$ErrorActionPreference = 'Stop' # Stops executing on error instead of silent continue.
Set-StrictMode -Version Latest # Enforces coding rules in expressions, scripts, and script blocks. Uninitialized variables are not permitted.
$fileContent = Get-Content $AssemblyInfoPath | Out-String
$assemblyVersionCapturePattern = 'AssemblyVersion\("\d+\.\d+\.\d+\.(\d+)"\)'
$assemblyVersionReplacePattern = '(AssemblyVersion\("\d+\.\d+\.\d+\.)\d+("\))'
$fileVersionReplacePattern = '(AssemblyFileVersion\("\d+\.\d+\.\d+\.)\d+("\))'
$currentRevision = [int][RegEx]::Match($fileContent, $assemblyVersionCapturePattern).Groups[1].Value
$newRevision = $currentRevision + 1
$fileContent = [RegEx]::Replace($fileContent, $assemblyVersionReplacePattern, '${1}' + $newRevision + '${2}')
$fileContent = [RegEx]::Replace($fileContent, $fileVersionReplacePattern, '${1}' + $newRevision + '${2}')
$fileContent | Out-File $AssemblyInfoPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment