Skip to content

Instantly share code, notes, and snippets.

@a5ync
Created March 15, 2017 21:32
Show Gist options
  • Save a5ync/b220887c0f003fabb4b809fab2ca4631 to your computer and use it in GitHub Desktop.
Save a5ync/b220887c0f003fabb4b809fab2ca4631 to your computer and use it in GitHub Desktop.
TeamCity: Inject github short hash to AssemblyInfo.cs files
$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