How do I use Team Build Properties in MSBuild?
Asked Answered
D

1

7

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)

Designing answered 29/8, 2011 at 15:12 Comment(0)
W
4

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.

Weigh answered 30/8, 2011 at 13:22 Comment(11)
I know how to do that in the workflow activity. What I'm asking is how to reference it as a Build Process Parameter in the Build Definition. For example Build Number Format has a default expression of $(BuildDefinitionName)_$(Date:yyyyMMdd)$(Rev:.r)Designing
Jim has just told you that you cannot just type that into a build process parameter. You could customize the build template and add a parameter, with Jim's expression as the default value.Lowrance
So there's no way of doing something like /p:SomeProperty=BuildDetail.BuildNumber.Subtring(...) without customizing the workflow? That seems unfortunate if so.Designing
@Christopher you could pass the appropriate VB expression into the MSBuild Arguments parameter. Parameter values don't have to be static constants, they can be any valid VB expression.Weigh
I'm trying that but getting errors or the expression as a literal in msbuild invocation trace. I'm not 100% sure what that would look like.Designing
I tried the same using the String.Format function as a parameter for "MSBuild Arguments" ... String.Format("/p:DeployIisAppPath=/mobile/changeset/{0}", BuildDetail.SourceGetVersion) ... but it doesn't work. Can I really write such functions into the "MSBuild Arguments" and they are evaluated?Halogen
Konrad and Chris are correct; placing a String.Format into the MSBuild Arguments will not work.Election
This answer is not correct, I cant add a VB expression as @JimLamb suggestCure
So basically, it is not possible to send any TFS Build property as an MSBuild argument? Must be custom activity?Foreclosure
@jJack, you don't have to create a custom activity. You just need to edit the build process XAML file. You can't enter VB expressions into the build process parameter GUI because those values just get passed through as literal strings.Weigh
@Jim- I wish there was a way. It'd be nice to put expressions there that get formatted by the workflow without having to edit the workflow.Designing

© 2022 - 2024 — McMap. All rights reserved.