问题
I can get the build number from IBuildDetail.BuildNumber but this is taken from the build definition and there fore might not include the revision number $(Rev:.r) or it might not be at the end.
So I would like to get this number without having to parse it from the build number. Is this property available any where during the build?
回答1:
Use the build variables.
From PowerShell use $Env:BUILD_BUILDNUMBER
if you’re using TFS 2015.
See MSDN: Use a PowerShell script to customize your build process
For previous versions: Team Foundation Build environment variables
回答2:
you can use following powershell script to parse Build number
[String]$myrev = $Env:BUILD_BUILDNUMBER
$result = $myrev.Substring($myrev.LastIndexOf('.') + 1)
Write-Host $result
来源:https://stackoverflow.com/questions/36360816/accessing-the-build-revision-number-in-powershell-script-during-tfs-build