Last active
February 23, 2017 10:59
-
-
Save abbottdev/fdea9d8bf6a9eb230b863bcbe641fafd to your computer and use it in GitHub Desktop.
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
$folder = 'D:\Development\Repos\MyWebsite\My Project\' | |
$paths = gci -Recurse -Include "AssemblyInfo.vb", "AssemblyInfo.cs" -Path $folder | |
foreach($path in $paths) { | |
# We need to filter out some invalid characters and possibly truncate the result and then we're good to go. | |
$info = (Get-Content $path) | |
$matches = ([regex]'AssemblyVersion\(\"([^\"]+)\"\)').Matches($info) | |
foreach ($match in $matches) { | |
if ($match.Success) { | |
#incase the build number contains 1.0.* | |
$newBuildNumber = $match.Groups[1].Value | |
[version]$version = $null | |
if ([Version]::TryParse($newBuildNumber, [ref]$version) -eq $true) { | |
Write-Host "##teamcity[buildNumber '$($version.Major).$($version.Minor).$($version.Build).$($version.Revision)']" | |
} | |
} | |
} | |
} |
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
$buildNumber = '%build.number%' | |
$paths = gci -Include "AssemblyInfo.vb", "AssemblyInfo.cs" -Recurse -File | |
foreach($path in $paths) { | |
# We need to filter out some invalid characters and possibly truncate the result and then we're good to go. | |
$info = (Get-Content $path) | |
$info = ([regex]'AssemblyVersion\(\"([^\"]+)\"\)').Replace($info, "AssemblyVersion(""$buildNumber"")") | |
$info = ([regex]'AssemblyFileVersion\(\"([^\"]+)\"\)').Replace($info, "AssemblyFileVersion(""$buildNumber"")") | |
Set-Content -Path $path -Value $info | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment