Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing build parameters to .wxs file to dynamically build wix installers

I am a student developer and I have built several installers for the company I am working with now. So I am fairly familiar with WIX. We recently decided to have a Build server that auto builds our solution. It builds both debug, and release, as well as Obfuscated (and non obfuscated) projects. And you really don't have to understand any of this. All you have to understand is that I have the same Wix project building different MSIs dynamically. So the way we build them is we call MSBuild.exe with several parameters. Parameters the wix project depends on.

So let's say we go into command prompt and write

C:\>\windows\Microsoft.NET\Framework\v3.5\MSBuild.exe MyApp.Install\MyApp.Install.wixproj /p:Configuration=Release /p:SpecialPath=Obfuscated /t:Build

The idea is that wix sees the "SpecialPath" parameter being assigned "Obfuscated"; and in the installer paths its source to ..\myApp\bin\$(var.SpecialPath)\myApp.exe which translates to ..\myApp\bin\Obfuscated\myApp.exe when built.

TheQuestion

How do you create those custom build parameters and have them passed to my .wxs file. As of now with this setup, $(var.SpecialPath) is not defined and the build CrashSplosions.

For obvious legal reasons I had to cut 90% of the project.wxs file out and rename some stuff, but for all intents and purposes this is what I have.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="myApp" Language="1033" Version="$(var.Version)" Manufacturer="myApp" UpgradeCode="$(var.UpgradeCode)">
<Package Id="*" InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="media.cab" EmbedCab="yes" />

<Directory Id="TARGETDIR" Name="SourceDir" >
  <Directory Id="ProgramFilesFolder">
    <Directory Id="INSTALLLOCATION" Name="myApp"> 

      <Component Id="myAppEXE" Guid="FD5EBC02-MY29-GUID-ACCA-61324C5F1B68">
        <RegistryKey Root="HKLM" Key="Software\MyApp">
          <RegistryValue Value="0" Type="string" KeyPath="yes"/>
        </RegistryKey>
        <File Id="MYAPPEXE" Name='myApp.exe' Source="..\myApp\bin\$(var.SpecialPath)\myApp.exe" />
      </Component>

      <Component Id="EngineDLL" Guid="*">
        <File Id="ENGINEDLL" Name='Engine.dll' Source="..\myApp\bin\$(var.Configuration)\Engine.dll" />
      </Component>
      <Component Id="CommonDLL" Guid="*">
        <File Id="COMMONDLL" Name='Common.dll' Source="..\myApp\bin\$(var.Configuration)\Common.dll" />
      </Component>
      
    </Directory>
  </Directory>
</Directory>

<Feature Id="ProductFeature" Title="myApp" Description='All' Display='expand' Level="1" ConfigurableDirectory='INSTALLLOCATION'>
  <ComponentRef Id="myAppEXE" />
  <ComponentRef Id="EngineDLL" />
  <ComponentRef Id="CommonDLL" />
</Feature>
</Product>
</Wix>
like image 998
Christopher Roy Avatar asked Jan 06 '10 21:01

Christopher Roy


1 Answers

The reason it's not working for you is that you are setting msbuild properties on the command line, which are not getting passed through as wix variables. MSBuild properties and wix variables are two different concepts.

One way to fix this is to ignore the concept of msbuild properties and use environment variables to pass values directly to candle.exe. You can use environment variables in your wxs file like this:

$(env.SpecialPath)

You can then launch your setup build from a batch file which prepares the necessary environment variables like this:

@echo off
setlocal

set SpecialPath=foo
set Configuration=Release
set msbuild=C:\windows\Microsoft.NET\Framework\v3.5\MSBuild.exe

%msbuild% test.wixproj /t:Build || goto ERROR

exit /b 0

:ERROR
echo Failed to build setup!
exit /b 1

Alternatively, if you prefer to pass parameters via msbuild properties, you should first take a look at the msbuild candle task documentation. It shows you can set values in your wixproj file like this:

<DefineConstants>Variable1=value1;Variable2=value2</DefineConstants>

This still requires you to hardcode values in the wixproj file though. If you want to pass the values as msbuild properties on the command line, then you should probably do something like this:

<DefineConstants>Variable1=$(value1);Variable2=$(value2)</DefineConstants>

and then pass /p:value1=foo /p:value2=bar on the command line, or define these msbuild properties elsewhere.

like image 189
Wim Coenen Avatar answered Oct 19 '22 02:10

Wim Coenen