Created
May 13, 2016 03:42
-
-
Save rosberglinhares/0a35087b6ba9165ff0df0618ffacbf0a to your computer and use it in GitHub Desktop.
Powershell script to increment assembly version
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 ( | |
[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