Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Wix property to TFS build location

Tags:

wix

tfs

tfsbuild

I have been trying to find an answer to my question and could not find it; hence I will put the solution here. I hope it is helpful to others.

Problem:

I want my Wix project to build in TFS 2010 build process. As part of this, I want the source files location for my Wix to point to the build location of the TFS. For example, I want:

<File Id="ABC" KeyPath="yes" source="C:\Builds\1\MyBuild\assembly.dll" />

to be:

<File Id="ABC" KeyPath="yes" source="$(var.TFSLOCATION)\assembly.dll" />

The 'TFSLOCATION' is a wix property that needs to be populated with the location of TFS build. This needs to happen during the build process, where the build location path is passed to the Wix project.

Solution:

I read the following article:

http://www.ageektrapped.com/blog/setting-properties-for-wix-in-msbuild/

So this is what I did to my Wix project file (wixproj):

In order to set wix property from TFS MSBuild process the wix project file needs two changes:

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <ProductVersion>3.5</ProductVersion>
    <SourceLocation Condition="'$(SourceLocation)' == '' ">UNKNOWN</SourceLocation>
    <ProjectGuid>{cae7e273-2de5-4a60-9c4f-9da5f094caf5}</ProjectGuid>
    <SchemaVersion>2.0</SchemaVersion>
    <OutputName>N4S.MSO.BAM.Installer</OutputName>
    <OutputType>Package</OutputType>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> 
  <OutputPath>bin\$(Configuration)\</OutputPath> 
  <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
  <DefineConstants>LOCATION=$(SourceLocation)</DefineConstants>
</PropertyGroup>

In the above xml, please note the following two lines:

<SourceLocation Condition="'$(SourceLocation)' == '' ">UNKNOWN</SourceLocation>

<DefineConstants>LOCATION=$(SourceLocation)</DefineConstants>

The first line specifies a property 'SourceLocation' and sets it to a default 'UNKNOWN' value, if is is not set. The second line defines a constant called 'LOCATION' in the 'Release' configuration. The value of this constant is set to the value of 'SourceLocation' property.

Now, you need to make the following changes to your Product.wxs file (or whatever the name of your wxs file is).

  • Define a wix property first.
<?define TFSLOCATION="$(var.LOCATION)"?>
  • Now, update the File elements.
<File Id="ABC" KeyPath="yes" source="$(var.TFSLOCATION)\assembly.dll" />

TFS 2010 build template change

  • Open the TFS 2010 build template.
  • Look for a task 'Run MSBuild for Project'.
  • Open the properties for this task and go to 'CommandLineArguments' property.
  • Set the value for this property to:
String.Format("/p:SourceLocation={0}", BinariesDirectory)

Done

You now have a wix property populated from your TFS build process.

like image 715
ansariwn Avatar asked Jul 18 '11 14:07

ansariwn


1 Answers

If you set a reference in your wixproj file to the project(s) you are building you can reference their target paths. So if you have two projects MyProject and MyProjectInstaller, set a reference in MyProjectInstaller to MyProject.

Now in the product.wxs file your File elements would look like this:

<File Id='EXE' Name='$(var.MyProject.TargetDir)\MyProject.exe' />
<File Id='DLL' Name='$(var.MyProject.TargetDir)\MyProject.dll' />
...

The benefit to this is that the target dir is correct regardless of whether you're building locally or on a build server.

like image 162
Corith Malin Avatar answered Oct 30 '22 07:10

Corith Malin