Skip to content

Instantly share code, notes, and snippets.

@a5ync
Created March 15, 2017 21:30
Show Gist options
  • Save a5ync/b2a45ac723243f315568e824de149c4c to your computer and use it in GitHub Desktop.
Save a5ync/b2a45ac723243f315568e824de149c4c to your computer and use it in GitHub Desktop.
TeamCity: Inject github short hash to project.json files of aspnet core
$rootDirectory="%teamcity.build.workingDir%"
$gitHash="%build.vcs.number%"
echo "githash is $gitHash"
$gitShortHash=$gitHash.Substring(0,7)
$listOfFiles = @(
"$rootDirectory\src\TestProject\project.json"
)
foreach($file in $listOfFiles)
{
$a = Get-Content $file -raw | ConvertFrom-Json
$currentVersion = $($a.version)
#clean up previous github hash
$currentVersion = $currentVersion -split '-',2 |select-object -first 1
echo "The current value of $file is $currentVersion"
$newVersion="$currentVersion-$gitShortHash"
echo "The new value of version for $file is $newVersion"
$a.version=$newVersion
#regenerate the file with modified node
$a|ConvertTo-Json -Depth 20|Set-Content $file
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment