Although our build machine uses a 32 bit operating system in some cases we build certain solutions on a 64 bit OS. One of these solutions includes a WiX project which packages a merge module for the C runtime libraries. On the 32 bit platform merge modules are located in “c:\Program Files\Common\Merge Modules”. In our WiX installer script (a WSX file) we package a merge module with a hardcoded path. This works fine on a 32 bit operating system.
However, it fails on a 64 bit operating system. There Visual Studio 2008 places the merge modules in “c:\Program Files (x86)\Common\Merge Modules”. As a consequence the hard code path doesn’t work.
I’d like to do set this path differently based on an environment variable. I chose “CommonProgramFiles(x86)” which exists on the 64 bit platform but is undefined on a 32 bit OS. Based on information I found at WiX’s web site, my first attempt looked as follows:
3 <?ifdef $(env.CommonProgramFiles(x86)) ?>
4 <!-- Variable is defined, we are building on 64 bit -->
5 <?define commonProgramFiles = "c:\Program Files (x86)\Common\" ?>
6 <?else?>
7 <!-- Variable is not defined, we are building on 32 bit -->
8 <?define commonProgramFiles = "c:\Program Files\Common\" ?>
9 <?endif?>
1 <File Source="$(var.commonProgramFiles)Merge Modules\Microsoft_VC90_CRT_x86.msm" >
2 ...
3 </File>
“Use <?ifdef?> first to see if it's defined. Don't use $() around it in an <?ifdef?>.”So I rewrote the the WiX script as follows:
3 <?ifdef env.CommonProgramFiles(x86) ?>
4 <!-- Variable is defined, we are building on 64 bit -->
5 <?define commonProgramFiles = "c:\Program Files (x86)\Common\" ?>
6 <?else?>
7 <!-- Variable is not defined, we are building on 32 bit -->
8 <?define commonProgramFiles = "c:\Program Files\Common\" ?>
9 <?endif?>
One further note: If you want use any of the WiX tools in a batch file, you may want to use %WIX% instead of a hard coded path to the toolset.
Jason, thank you very much for your help in sorting this out!
P.S. I haven’t forgotten about the mini-series of blogs about WCF-based services I’ve started a few days ago. It’s still coming!
Wouldn't it be easier to copy the files in a local build directory?
ReplyDeleteYou can refer to other variables when defining a variable (in WiX 3.5 at least) so you don't have to hard-wire the paths:
ReplyDeleteThe tip "Don't use $() around it in an " really saved my day thanks!!!
ReplyDeleteExcellent, I've been having the problems with the ifdef/env combination for a day...
ReplyDeleteShould be \Common Files\ not \Common\
ReplyDelete