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. 
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}\${}.sln">

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

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=".
  • 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.
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.