Friday, June 1, 2012

Define a preprocessor variable in TFS

Last week I got the following question from a colleague:
Do you have an idea how to define a preprocessor variable in TFS 2010?  Actually, these variables is used by Wix installer in the following project. 
clip_image001
Apparently it is not possible to add this as a classical Msbuild argument (it is possible to add a constant but not define its value). In the nant build script, this is defined like this :
<msbuild project="${src.dir}\${project.name}.sln">

<property name="SolutionDefineConstants" value="Version=${project.version};BinDir=${out.dir}\\" />

</msnbuild>
There are 2 options I’m aware of to solve this problem:
  • Inside the build definition you can pass the parameter for msbuild like /p:DefineConstants="Version=1.2.1.0".
image
  • If the value you want to provide is only available inside the build definition itself(e.g. the build number), you’ll have to open the Build Definition Template and add an extra assign activity to override the MSBuildArguments value.
image
Here is an example where I set the Version constant to the BuildNumber:
MSBuildArguments + " /p:DefineConstants=""Version=" + BuildDetail.BuildNumber + """"

1 comment:

Imran Hashmi said...
This comment has been removed by a blog administrator.