Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Team Build Properties in MSBuild?

I have a simple tfs-2010 build definition using the default process template. In it I defined the Build Number Format using $(BuildID) to define part of the computed field. This works and I can see what BuildID's value is.

Now I try to pass the BuildID property to MSBuild as an argument:

/p:SomeProperty=$(BuildID)

However when I look at the build log I see SomeProperty literally equals $(BuildID) rather then the value of BuildID.

What am I missing?

Update for clarity: What I'm asking is how to reference as a Build Process Parameter in the Build Definition. For example Build Number Format has a default expression of $(BuildDefinitionName)_$(Date:yyyyMMdd)$(Rev:.r)

like image 449
Christopher Painter Avatar asked Aug 29 '11 15:08

Christopher Painter


1 Answers

You need to use a VB.NET expression. For example:

String.Format("/p:SomeProperty={0}", BuildDetail.BuildNumber)

The Build Number tokens, e.g. $(BuildDefinitionName), are specific to the Build Number Format process parameter. They aren't tokens that you can use anywhere else in the build process. Most are available in the BuildDetail object or from the environment. The Build Id is a bit of a special case, however. It comes from the identity column of the builds table and isn't directly exposed in our public API. You could extract it from the BuildNumber, like this:

BuildDetail.BuildNumber.Substring(BuildDetail.BuildNumber.LastIndexOf('/') + 1)

Note that you would need to do this in the XAML directly rather than putting a VB expression into the build process parameter editor GUI. That's because those values just get passed through as literal strings.

like image 56
Jim Lamb Avatar answered Oct 01 '22 01:10

Jim Lamb