Last active
November 7, 2017 21:37
-
-
Save leachdaniel/639d5f83e4f968a7dccc9d755f1f4b09 to your computer and use it in GitHub Desktop.
Update Assembly Info
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
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory = $true)] | |
[string]$buildNumberString, | |
[Parameter(Mandatory = $false)] | |
[string]$informationalVersionString | |
) | |
$ErrorActionPreference = 'Stop'; | |
Write-Host "Updating assembly versions" | |
[Version]$ver = $null | |
if (-not ([Version]::TryParse($buildNumberString + ".0", [ref]$ver))) | |
{ | |
Write-Host "Unable to parse a valid Version number from the buildNumber '$buildNumberString' defaulting to 1.0" | |
$ver = [Version]::Parse("1.0") | |
} | |
$versionString = $ver.ToString() | |
if(-not $informationalVersionString) { | |
$informationalVersionString = $versionString | |
Write-Host "informationalVersionString not provided using $versionString" | |
} | |
Function Get-AssemblyAttributeString ($type) { | |
if ($type -eq "Informational") { | |
$versionString = $informationalVersionString; | |
} | |
return "Assembly$($type)Version(""$versionString"")"; | |
} | |
Get-ChildItem -Recurse -Filter AssemblyInfo.cs | Where-Object { $_.FullName -notlike "*.Tests*" } | ForEach-Object { | |
$filename = $_.Directory.ToString() + '\' + $_.Name | |
$content = Get-Content $filename | Out-String | |
Write-Host -NoNewLine "$informationalVersionString ($buildNumberString) -> $filename" | |
$groups = new-object system.collections.arraylist | |
$content = ([regex]'\bAssembly(File|Informational)?Version\("[^"]+"\)').Replace($content, { | |
[void]$groups.Add($args[0].Groups[1].Value) | |
return (Get-AssemblyAttributeString $args[0].Groups[1].Value) | |
}) | |
@("", "File", "Informational") | ForEach-Object { | |
if ($groups -notcontains $_) { | |
Write-Host -NoNewLine ", added Assembly$($_)Version" | |
$content = $content + "`n[assembly: $(Get-AssemblyAttributeString $_ ))]" | |
} | |
} | |
Write-Host | |
$content | Out-File $filename -Encoding "UTF8" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment