1

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.

Alezis
  • 2,659
  • 3
  • 27
  • 34
  • Is this question similar to http://stackoverflow.com/questions/41763224/tfs-2015-the-var-sourcelocation-variable-is-not-available-at-gated-check-in? – Cece Dong - MSFT Jan 23 '17 at 09:24
  • @Cece - MSFT, This question about updating dll with commit/changeset id. Why you down-voted ? Could you explain, what is wrong ? – Alezis Jan 23 '17 at 12:10

2 Answers2

0

If your question is similar to your another post TFS 2015. the $(var.SourceLocation) variable is not available at gated-check in, that want to get the changeset id that hasn't checked in during gated check-in, then it's impossible in a single build.

If you don't use gated check in, then you can use $Env:BUILD_SOURCEVERSION in a powershell script to set the AssemblyVersion. Here is already a script at the website below, you can refer to it:

https://github.com/wulfland/ScriptRepository/blob/master/TFSBuild/TFSBuild/AssemblyVersion/Set-AssemblyVersion/Set-AssemblyVersion.ps1

Community
  • 1
  • 1
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
0

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

Alezis
  • 2,659
  • 3
  • 27
  • 34
  • Is this script can be modified to change only product version instead of file and product version? – Dima Grigoriev Aug 14 '17 at 07:39
  • What do you mean by "product version" ? This script can update assembly version and file version of assembly. It hits 'AssemblyVersion' and 'AssemblyFileVersion' attributes. You can change logic to whatever you want by changing regex. If you need only file version, then use something like "FileVersion\(""([0-9]+)\.([0-9]+).+""" – Alezis Aug 15 '17 at 09:05