Search code examples
tfsazure-devopstfsbuildtfs-2015

TFS 2015 build vNext update file version with commit id


Do you know how inject commit id into file version, so every assembly would heve version like 2.0.6565.0 where 6565 is related to C6565commit ID in TFS ?

It looks some power shell script is needed.


Solution

  • Finally I created my own PS script based on this post. The idea update version in all files with assembly info

    $CommitId = ([string]$env:BUILD_SOURCEVERSION) -replace "[^0-9]+", ""
    $AllVersionFiles = Get-ChildItem $SourceDir AssemblyInfo.cs -recurse
    $regexToFindVersion = "Version\(""([0-9]+)\.([0-9]+).+"""
    
    foreach ($file in $AllVersionFiles) 
    {
        Write-Host "Processing " $file.FullName
    
        (Get-Content $file.FullName) |
        %{$_ -replace $regexToFindVersion, ('Version("$1.$2.0.' + $CommitId + '"') } |
        Set-Content $file.FullName -Force
    }
    

    Full script can be found here.

    The script must be placed before building project: BuildSteps