Wix Burn:如何将32位和64位的安装包制作成一个安装包

由于Windows Installer不是平台独立的(即区分32-bit和64-bit),因此用Wix制作的安装包在编译不能像.net应用那样采用Any CPU编译,而必须制定是目标Platform是x86还是x64。这决定了我们的程序必须针对32-bit和64-bit的操纵系统提供两个不同的版本的安装包,一个32位的,一个64位的。如果业务上允许提供两个安装包,那没问题。我这里要说的是如何制作一个安装包可以同时安装在两种平台上。

3.6版开始,Wix引入了一个新的功能-“the Burn bootstrapper/chaining engine”。Burn的主要功能是将多个安装包打包到一起,实现一键安装。这些安装包可以是我们的应用程序安装包,也可以是一些运行时的支持库,比如.Net Framework, C++ runtime之类,或者是像数据库、IIS之类的应用。

那么利用Burn我们可以32位和64位的两个安装打包到一起形成一个安装包。关于如何打包的详细说明请参考“http://wixtoolset.org/documentation/manual/v3/bundle/”,我这里只是结合一个简单的例子来分享一些实际使用过程中遇到的问题和解决方案。

步骤1:添加一个Bootstrapper Project。

Bootstrapper从字面理解就是一个启动器,而实际上它就是Wix的Burn功能。假定我们已经有了两个安装包,接下来就是:

image

步骤2:添加对安装包项目的引用。

安装项目的引用能方便我们在步骤3中引用安装包的输出文件路径。

image

步骤3:打开Bundle.wxs文件添加安装包文件的引用

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Bundle Name="WixBootstrapperExample" Version="1.0.0.0" Manufacturer="Rader" UpgradeCode="1c99d366-abd8-4946-9573-b01a9188301b" >
    <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" />

    <Chain>
      <!-- TODO: Define the list of chained packages. -->
      <MsiPackage SourceFile="$(var.Setup_x86.TargetPath)"  Vital="yes" />
      <MsiPackage SourceFile="$(var.Setup_x64.TargetPath)"  Vital="yes" />
    </Chain>
  </Bundle>
</Wix>

步骤4:添加安装条件,控制32位、64位安装包的执行

Burn在执行一个安装包(Msi)之前会先检查安装条件(InstallCondition),如果条件不满足就不会执行。针对本例我们可以将执行条件设定为32位OS或64位OS上才执行,具体如下:

<MsiPackage SourceFile="$(var.Setup_x86.TargetPath)"  Vital="yes" DisplayInternalUI="yes" Visible="yes" Compressed="no" InstallCondition="NOT VersionNT64" />
     <MsiPackage SourceFile="$(var.Setup_x64.TargetPath)"  Vital="yes" DisplayInternalUI="yes" Visible="yes" Compressed="no" InstallCondition="VersionNT64" />

“VersionNT64”是Burn的内置变量,当Bootstrapper安装程序在64位机器上执行的时候该值会被设定为真。

PS:

完整的Bootstrapper项目的代码:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Bundle Name="WixBootstrapperExample" Version="1.0.0.0" Manufacturer="Rader" UpgradeCode="1c99d366-abd8-4946-9573-b01a9188301b"
          DisableRemove="yes" DisableModify="yes" DisableRepair="yes">
    <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" />

    <Chain>
      <!-- TODO: Define the list of chained packages. -->
      <MsiPackage SourceFile="$(var.Setup_x86.TargetPath)"  Vital="yes" DisplayInternalUI="yes" Visible="yes" Compressed="no" InstallCondition="NOT VersionNT64" />
      <MsiPackage SourceFile="$(var.Setup_x64.TargetPath)"  Vital="yes" DisplayInternalUI="yes" Visible="yes" Compressed="no" InstallCondition="VersionNT64" />
    </Chain>
  </Bundle>
</Wix>

相关代码在Win7(64-bit)/WindowsServer2003(32-bit) +VS2013+Wix 3.8下测试通过。

posted @ 2014-08-22 17:16  排骨虾  阅读(1094)  评论(0编辑  收藏  举报