Skip to content

Instantly share code, notes, and snippets.

@clairernovotny
Created June 20, 2015 13:20
Show Gist options
  • Save clairernovotny/b98298ae9dcb2793e95a to your computer and use it in GitHub Desktop.
Save clairernovotny/b98298ae9dcb2793e95a to your computer and use it in GitHub Desktop.
Param(
[string]$pathToSearch = $env:BUILD_SOURCESDIRECTORY,
[string]$buildNumber = $env:BUILD_BUILDNUMBER
)
try
{
$buildPattern = "\d+\.\d+\.\d+\.\d+"
if ($buildNumber -match $buildPattern -ne $true) {
Write-Host "Could not extract a version from [$buildNumber] using pattern [$buildPattern]"
exit 1
} else {
$extractedBuildNumber = $Matches[0]
Write-Host "Using version $extractedBuildNumber"
# Update Assembly Infos
$searchFilter = "AssemblyInfo.*"
gci -Path $pathToSearch -Filter $searchFilter -Recurse | %{
Write-Host " -> Changing $($_.FullName)"
# remove the read-only bit on the file
sp $_.FullName IsReadOnly $false
# run the regex replace
(gc $_.FullName -Encoding UTF8) | % { $_ -replace $buildPattern, $extractedBuildNumber } | sc $_.FullName -Encoding UTF8
} | out-null
# Update Package.appxmanifest
$searchFilter = "Package.appxmanifest"
gci -Path $pathToSearch -Filter $searchFilter -Recurse | %{
Write-Host " -> Changing $($_.FullName)"
# remove the read-only bit on the file
sp $_.FullName IsReadOnly $false
# run the regex replace
(gc $_.FullName -Encoding UTF8) | % { $_ -replace "Version=`"$buildPattern`"", "Version=`"$extractedBuildNumber`"" } | sc $_.FullName -Encoding UTF8
} | out-null
# Update Nuspecs
$searchFilter = "*.nuspec"
gci -Path $pathToSearch -Filter $searchFilter -Recurse | %{
Write-Host " -> Changing $($_.FullName)"
# remove the read-only bit on the file
sp $_.FullName IsReadOnly $false
# run the regex replace
(gc $_.FullName -Encoding UTF8) | % { $_ -replace "<version>$buildPattern", "<version>$extractedBuildNumber" } | sc $_.FullName -Encoding UTF8
} | out-null
Write-Host "Done!"
}
}
catch {
Write-Host $_
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment