WiX 技巧和窍门 [英] WiX tricks and tips

查看:27
本文介绍了WiX 技巧和窍门的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经使用 WiX 有一段时间了,尽管通常会抱怨易用性,但它运行得相当好.我正在寻找关于以下方面的有用建议:

We've been using WiX for a while now, and despite the usual gripes about ease of use, it's going reasonably well. What I'm looking for is useful advice regarding:

  • 设置 WiX 项目(布局、参考、文件模式)
  • 将 WiX 集成到解决方案和构建/发布流程中
  • 为新安装和升级配置安装程序
  • 您想分享的任何优秀的 WiX 技巧

推荐答案

  1. 将变量保存在单独的 wxi 包含文件中.支持重用,更快地找到变量,并且(如果需要)允许通过外部工具更轻松地操作.

  1. Keep variables in a separate wxi include file. Enables re-use, variables are faster to find and (if needed) allows for easier manipulation by an external tool.

为 x86 和 x64 构建定义平台变量

Define Platform variables for x86 and x64 builds

<!-- Product name as you want it to appear in Add/Remove Programs-->
<?if $(var.Platform) = x64 ?>
  <?define ProductName = "Product Name (64 bit)" ?>
  <?define Win64 = "yes" ?>
  <?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
<?else ?>
  <?define ProductName = "Product Name" ?>
  <?define Win64 = "no" ?>
  <?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
<?endif ?>

  • 将安装位置存储在注册表中,以便进行升级以找到正确的位置.例如,如果用户设置自定义安装目录.

  • Store the installation location in the registry, enabling upgrades to find the correct location. For example, if a user sets custom install directory.

     <Property Id="INSTALLLOCATION">
        <RegistrySearch Id="RegistrySearch" Type="raw" Root="HKLM" Win64="$(var.Win64)"
                  Key="Software\Company\Product" Name="InstallLocation" />
     </Property>
    

    注意:WiX 专家Rob Mensching 发布了一个优秀的博客条目,其中详细介绍了修复了从命令行设置属性时的边缘情况.

    Note: WiX guru Rob Mensching has posted an excellent blog entry which goes into more detail and fixes an edge case when properties are set from the command line.

    使用 1. 2. 和 3. 的示例

    Examples using 1. 2. and 3.

    <?include $(sys.CURRENTDIR)\Config.wxi?>
    <Product ... >
      <Package InstallerVersion="200" InstallPrivileges="elevated"
               InstallScope="perMachine" Platform="$(var.Platform)"
               Compressed="yes" Description="$(var.ProductName)" />
    

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="$(var.PlatformProgramFilesFolder)">
        <Directory Id="INSTALLLOCATION" Name="$(var.InstallName)">
    

  • 最简单的方法总是 主要升级,因为它允许在单个 MSI 中进行新安装和升级.UpgradeCode 固定为唯一的 Guid,永远不会改变,除非我们不想升级现有产品.

  • The simplest approach is always do major upgrades, since it allows both new installs and upgrades in the single MSI. UpgradeCode is fixed to a unique Guid and will never change, unless we don't want to upgrade existing product.

    注意:在 WiX 3.5 中有一个新的MajorUpgrade 元素使生活 甚至更容易

    Note: In WiX 3.5 there is a new MajorUpgrade element which makes life even easier!

    在添加/删除程序中创建图标

    Creating an icon in Add/Remove Programs

    <Icon Id="Company.ico" SourceFile="..\Tools\Company\Images\Company.ico" />
    <Property Id="ARPPRODUCTICON" Value="Company.ico" />
    <Property Id="ARPHELPLINK" Value="http://www.example.com/" />
    

  • 在发布版本中,我们对安装程序进行版本控制,将 msi 文件复制到部署目录.使用从 AfterBuild 目标调用的 wixproj 目标的示例:

  • On release builds we version our installers, copying the msi file to a deployment directory. An example of this using a wixproj target called from AfterBuild target:

    <Target Name="CopyToDeploy" Condition="'$(Configuration)' == 'Release'">
      <!-- Note we append AssemblyFileVersion, changing MSI file name only works with Major Upgrades -->
      <Copy SourceFiles="$(OutputPath)$(OutputName).msi" 
            DestinationFiles="..\Deploy\Setup\$(OutputName) $(AssemblyFileVersion)_$(Platform).msi" />
    </Target>
    

  • 使用 heat 收集带有通配符 (*) Guid 的文件.如果您想在多个项目中重用 WXS 文件(请参阅我对同一产品的多个版本的回答)很有用.例如,此批处理文件会自动收集 RoboHelp 输出.

  • Use heat to harvest files with wildcard (*) Guid. Useful if you want to reuse WXS files across multiple projects (see my answer on multiple versions of the same product). For example, this batch file automatically harvests RoboHelp output.

    @echo off  
    robocopy ..\WebHelp "%TEMP%\WebHelpTemp\WebHelp" /E /NP /PURGE /XD .svn  
    "%WIX%bin\heat" dir "%TEMP%\WebHelp" -nologo -sfrag -suid -ag -srd -dir WebHelp -out WebHelp.wxs -cg WebHelpComponent -dr INSTALLLOCATION -var var.WebDeploySourceDir 
    

    发生了一些事情,robocopy 在收获之前剥离了 Subversion 工作副本元数据;-dr 根目录引用设置为我们的安装位置而不是默认的 TARGETDIR;-var 用于创建一个变量来指定源目录(web 部署输出).

    There's a bit going on, robocopy is stripping out Subversion working copy metadata before harvesting; the -dr root directory reference is set to our installation location rather than default TARGETDIR; -var is used to create a variable to specify the source directory (web deployment output).

    通过使用 Strings.wxl 进行本地化,可以轻松将产品版本包含在欢迎对话框标题中.(来源:saschabeaumont.添加,因为这个很棒的提示隐藏在评论中)

    Easy way to include the product version in the welcome dialog title by using Strings.wxl for localization. (Credit: saschabeaumont. Added as this great tip is hidden in a comment)

    <WixLocalization Culture="en-US" xmlns="http://schemas.microsoft.com/wix/2006/localization">
        <String Id="WelcomeDlgTitle">{\WixUI_Font_Bigger}Welcome to the [ProductName] [ProductVersion] Setup Wizard</String>
    </WixLocalization>
    

  • 省去一些痛苦并遵循 Wim Coehen 的建议 每个文件一个组件.这也允许您省略(或通配符 *)组件 GUID.

  • Save yourself some pain and follow Wim Coehen's advice of one component per file. This also allows you to leave out (or wild-card *) the component GUID.

    Rob Mensching 有一个 简洁的方法通过搜索value 3快速追踪MSI日志文件中的问题.请注意有关国际化的评论.

    Rob Mensching has a neat way to quickly track down problems in MSI log files by searching for value 3. Note the comments regarding internationalization.

    在添加条件功能时,将默认功能级别设置为 0(禁用),然后将条件级别设置为您想要的值更直观.如果您将默认功能级别设置为 >= 1,则条件级别必须为 0 才能禁用它,这意味着条件逻辑必须与您期望的相反,这可能会令人困惑:)

    When adding conditional features, it's more intuitive to set the default feature level to 0 (disabled) and then set the condition level to your desired value. If you set the default feature level >= 1, the condition level has to be 0 to disable it, meaning the condition logic has to be the opposite to what you'd expect, which can be confusing :)

    <Feature Id="NewInstallFeature" Level="0" Description="New installation feature" Absent="allow">
      <Condition Level="1">NOT UPGRADEFOUND</Condition>
    </Feature>
    <Feature Id="UpgradeFeature" Level="0" Description="Upgrade feature" Absent="allow">
      <Condition Level="1">UPGRADEFOUND</Condition>
    </Feature>
    

  • 这篇关于WiX 技巧和窍门的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆