Created
May 12, 2016 03:38
-
-
Save rosberglinhares/f5d873a73953775937942a42399996eb to your computer and use it in GitHub Desktop.
Powershell script to change assembly and file 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[]] $AssemblyInfoFilesPath, | |
[Parameter(Mandatory=$true)] | |
[Version] $Version | |
) | |
$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. | |
function Change-AssemblyVersion([string] $assemblyInfoFilePath, [Version] $newVersion) | |
{ | |
$fileContent = Get-Content $assemblyInfoFilePath | Out-String | |
$assemblyVersionReplacePattern = '(AssemblyVersion\(")\d+\.\d+\.\d+\.\d+("\))' | |
$fileVersionReplacePattern = '(AssemblyFileVersion\(")\d+\.\d+\.\d+\.\d+("\))' | |
$fileContent = [RegEx]::Replace($fileContent, $assemblyVersionReplacePattern, '${1}' + $newVersion + '${2}') | |
$fileContent = [RegEx]::Replace($fileContent, $fileVersionReplacePattern, '${1}' + $newVersion + '${2}') | |
$fileContent | Out-File $assemblyInfoFilePath | |
} | |
function Normalize-Version([Version] $version) | |
{ | |
$newBuild = If ($version.Build -ge 0) { $version.Build } Else { 0 } | |
$newRevision = If ($version.Revision -ge 0) { $version.Revision } Else { 0 } | |
New-Object Version($version.Major, $version.Minor, $newBuild, $newRevision) | |
} | |
$Version = Normalize-Version $Version | |
$AssemblyInfoFilesPath | ForEach-Object { Change-AssemblyVersion $_ $Version } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you need to set the path of "AssemblyInfo.cs" file, not ".dll" files