Skip to content

Instantly share code, notes, and snippets.

@abbottdev
Last active February 23, 2017 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abbottdev/fdea9d8bf6a9eb230b863bcbe641fafd to your computer and use it in GitHub Desktop.
Save abbottdev/fdea9d8bf6a9eb230b863bcbe641fafd to your computer and use it in GitHub Desktop.
$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)']"
}
}
}
}
$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