Created
March 15, 2017 21:32
-
-
Save a5ync/b220887c0f003fabb4b809fab2ca4631 to your computer and use it in GitHub Desktop.
TeamCity: Inject github short hash to AssemblyInfo.cs files
This file contains hidden or 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
$githubHash="%build.vcs.number%" | |
$gitShortHash=$githubHash.Substring(0,7) | |
$rootDirectory="%teamcity.build.workingDir%" | |
$listOfFiles = @( | |
"$rootDirectory\TestProject\Properties\AssemblyInfo.cs" | |
) | |
foreach($file in $listOfFiles) | |
{ | |
echo "replacing $file" | |
#if the last line already includes AssemblyInformationalVersion, re-add it | |
$lastLine = Get-Content $file|select-object -last 1 | |
echo "last line is $lastLine" | |
if($lastLine.Contains("AssemblyInformationalVersion")) | |
{ | |
#replace the existing without the last line | |
$existingContent=Get-Content $file|select-object -SkipLast 1 | |
$existingContent|out-file $file -encoding UTF8 | |
} | |
echo "adding content" | |
Add-Content $file "[assembly: AssemblyInformationalVersion(`"$gitShortHash`")]" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment