0

I am trying to get the Source Version Changeset number from TFS. I am using a PowerShell script to add the AssemblyInformationalVersion. I have tried using $env:TF_BUILD SOURCEGETVERSION but this dosen't work it just return blank. We are using TFS 2012 with a custom build template calling the PowerShell scripts (http://www.colinsalmcorner.com/post/build-script-hooks-for-tfs-2012-builds)

I really want to keep everything within the PowerShell Script

Scott E
  • 185
  • 1
  • 12

2 Answers2

0

No, this can't be achieved simply by an environment variable in a powershell script . You need to create a custom task, follow the steps below to have a try:

  1. Get the latest changeset number in your TFS version control. You can just get it by using TFS API. Please see this thread for detailed information: Programmatically retrieve the latest changeset number available in a workspace
  2. You can write another small program to modify your FileVersion field in the .rc file be the changeset number you get in Setp1.

Or you can try the method descried by Ivan's answer in this question Versioning .NET builds


Add more similar quesitons in SO for your reference:

Community
  • 1
  • 1
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
0

The answer is in the article you referred to(The Challenge 2 – Environment Variables).

When I created a script for a 2013 build to version the assemblies, I relied on the fact that the 2013 build sets some environment variables that you can use in your scripts.You can see I’m getting $env:TF_BUILD_BUILDNUMBER. Well, in the 2012 workflow, these variables aren’t set, so you have to add an activity to do it.

That's why $env:TF_BUILD SOURCEGETVERSION returns blank, so you just need to follow the steps in Challenge 2 to set it.

Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60