Created
July 8, 2014 21:02
-
-
Save bpatra/1ae1aac8c9b9508844ab to your computer and use it in GitHub Desktop.
Details of the functions used in the PatchAssemblyInfo PSake task
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
function GetRevisionNumber { | |
$major = "1" | |
$minor = "0" | |
#we use the environment variable BUILD_NUMBER provided by teamcity, use -1 is not found to test locally the process | |
$patch= if ([string]::IsNullOrEmpty($env:BUILD_NUMBER)) { "-1" } else { $env:BUILD_NUMBER } | |
$major + "." + $minor + "." + $patch | |
} | |
function PatchFile ([string] $pattern, [string] $replaceString, [string] $fullPath){ | |
if(!(Test-Path $fullPath)) { #always test-path for build scripts | |
throw "cannot find the path at " + $fullPath | |
} | |
$matchCount = 0 | |
$regex = New-Object -TypeName "System.Text.RegularExpressions.Regex" -ArgumentList $pattern | |
(Get-Content $fullPath -Encoding UTF8) | Foreach-Object { | |
if($regex.IsMatch($_)){ | |
$matchCount = $matchCount + 1 | |
} | |
$regex.Replace($_,$replaceString) | |
} | Set-Content $fullPath -Encoding UTF8 | |
if($matchCount -eq 0){ #check that some lines has been patched by the function | |
throw "no line found for patching " + $fullPath | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment