Search code examples
msbuildwixtfsbuild

TFS Build Definition with WIX and .build file


I'm trying to get a build working on a TFS server to spit out our .msi. Locally I would run:

C:\Dev\Installer>msbuild /t:Build;PublishWebsite;Harvest;WIX setup.build

which uses 'setup.build':

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build"
       xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup >
    <WebSiteSource>..\FrontEnd\</WebSiteSource>
    <SetupF>..\Setup\</SetupF>
    <PublishF>publish\</PublishF>
    <Publish>$(SetupF)$(PublishF)</Publish>
    <WebSiteContentCode>WebSiteContent.wxs</WebSiteContentCode>
  <WebSiteContentObject>WebSiteContent.wixobj</WebSiteContentObject>
     <EnableProjectHarvesting>True</EnableProjectHarvesting>
  <MsiOut>bin\Release\Dashboard.msi</MsiOut>
  </PropertyGroup>
  <!-- Defining group of temporary files which is the content of the web site. -->
  <ItemGroup>
    <WebSiteContent Include="$(WebSiteContentCode)" />
  </ItemGroup>

  <!-- The list of WIX input files -->
  <ItemGroup>
    <WixCode Include="Product.wxs" />
    <WixCode Include="$(WebSiteContentCode)" />
      <WixCode Include="ProductUI.wxs" />
        <WixCode Include="IISConfiguration.wxs" />

  </ItemGroup>

   <ItemGroup>
    <WixObject Include="Product.wixobj" />
    <WixObject Include="$(WebSiteContentObject)" />
      <WixObject Include="ProductUI.wixobj" />
        <WixObject Include="IISConfiguration.wixobj" />

  </ItemGroup>

   <Target Name="Build">
    <!-- Compile whole solution in release mode -->
    <MSBuild
        Projects="..\WebDashboard.sln"
        Targets="ReBuild"
        Properties="Configuration=Release;Platform=Any CPU" />
  </Target>

    <Target Name="PublishWebsite">
        <!-- Remove complete publish folder in order to 
             be sure that evrything will be newly compiled -->
        <Message Text="Removing publish directory: $(SetupF)"/>
        <RemoveDir Directories="$(SetupF)" ContinueOnError="false" />
        <Message Text="Start to publish website" Importance="high" />
        <MSBuild
            Projects="..\\FrontEnd\WebDashboard.csproj"
            Targets="ResolveReferences;_CopyWebApplication"
            Properties="OutDir=$(Publish)bin\;WebProjectOutputDir=
                            $(Publish);Configuration=Release;Platform=AnyCPU" />
    </Target>
     <Target Name="Harvest">
    <!-- Harvest all content of published result -->
        <Exec
            Command='"$(WiX)bin\heat" dir $(Publish) -dr INSTALLFOLDER -ke -srd -cg MyWebWebComponents -var var.publishDir -gg -out $(WebSiteContentCode)'
            ContinueOnError="false"
            WorkingDirectory="." />
    </Target>
    <Target Name="WIX">
        <Exec
            Command='"$(WiX)bin\candle" -ext WixIISExtension -dpublishDir=$(Publish) -dMyWebResourceDir=. @(WixCode, &apos; &apos;)'
            ContinueOnError="false"
            WorkingDirectory="." />
        <Exec
            Command='"$(WiX)bin\light" -ext WixIISExtension -ext WixUIExtension -out $(MsiOut) @(WixObject, &apos; &apos;)'
            ContinueOnError="false"
            WorkingDirectory="." />


  <!-- A message at the end -->
  <Message Text="Install package has been created." />
    </Target>
    <Target Name="DeleteTmpFiles">
        <RemoveDir Directories="$(Publish)" ContinueOnError="false" />
        <RemoveDir Directories="$(SetupF)" ContinueOnError="false" />
        <Delete Files="@(WixObject);@(WebSiteContent)" />
    </Target>
</Project>

How do I run this in a build definition on TFS? I've tried using the normal command prompt but it says msbuild is not recognized. Is there anything else I could use or does anyone know the full path to the msbuild tool?


Solution

  • Fixed it by using the Command Line Task and setting 'Tool' to

    C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe
    

    and Arguments to

     /t:Build;PublishWebsite;Harvest;WIX setup.build
    

    then in advanced setting the 'Working Folder' to the location of the setup.build file.