[译]:WiX Toolset入门——使用WiX标准引导应用
博客分类: 官方教程
返回目录索引
本文内容为官方文档多部分整合:
原文链接:
使用WiX标准引导应用
正如上一节介绍,每一个捆绑包都需要一个bootstrapper应用dll来驱动Burn引擎。创建自定义bootstrapper应用需要开发者自己写本机代码或托管代码。因此,WiX toolset提供了标准的bootstrapper应用,同时开发者还可以以特定的方式使用和定制。
WiX有以下几种不一样的WiX标准bootstrapper应用。
- WixStandardBootstrapperApplication.RtfLicense - 在欢迎界面中显示许可协议,类似于 WixUI Advanced.
- WixStandardBootstrapperApplication.HyperlinkLicense - 在欢迎界面中显示许可协议的链接,并提供更现代和流线型的外观。
- WixStandardBootstrapperApplication.HyperlinkSidebarLicense - 基于 HyperlinkLicense 改进,在初始界面中提供了更大的界面和图片。
- WixStandardBootstrapperApplication.RtfLargeLicense - 类似于 RtfLicense ,但具有更大的界面,并且提供显示版本号选项。
- WixStandardBootstrapperApplication.HyperlinkLargeLicense - 类似于 HyperlinkLicense,但具有更大的界面,并提供显示版本号选项。
- WixStandardBootstrapperApplication.Foundation - 空内容,需要开发者自己提供主题文件来定制外观和感觉。
要使用WiX标准bootstrapper应用,必须利用<BootstapperApplicationRef>
元素引用上面的一个内容。如下代码为使用bootstrapper应用来显示许可的示例:
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Bundle>
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" />
<Chain>
</Chain>
</Bundle>
</Wix>
HyperlinkLargeTheme, HyperlinkSidebarTheme, 和 RtfLargeTheme 可以在欢迎界面添加版本号显示,代码如下:
注:官网示例有误,使用的RtfLicense,这个是无法显示版本号的;此处已修改。
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Bundle>
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLargeLicense">
<bal:WixStandardBootstrapperApplication
LicenseFile="path\to\license.rtf"
ShowVersion="yes"
/>
</BootstrapperApplicationRef>
<Chain>
</Chain>
</Bundle>
</Wix>
当生成捆绑包时,WixBalExtension必须提供。假如上述代码都在一个文件中(“example.wxs”),则可以使用以下步骤创建“example.exe”捆绑包:
candle.exe example.wxs -ext WixBalExtension
light.exe example.wixobj -ext WixBalExtension
后面几节将会介绍如何使用WiX标准bootstrapper应用定制自己的捆绑包。
指定WiX标准bootstrapper应用的许可协议
WiX标准bootstrapper应用(WixStdBA)支持显示一个RTF文件格式的许可协议,或者链接到一个许可协议文件(本地或在网络上)。许可协议文件通过<bal:WixStandardBootstrapperApplication>
元素的LicenseFile
或LicenseUrl
属性指定。
当使用显示RTF许可协议的WixStdBA主题时,强烈建议重写许可协议,因为它默认使用的是一个假的替代文本。下面示例为使用一个path\to
文件夹下的license.rtf文件 —— 本示例中文件路径是相对与链接器的路径:
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Bundle>
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense">
<bal:WixStandardBootstrapperApplication
LicenseFile="path\to\license.rtf"
LogoFile="path\to\customlogo.png"
/>
</BootstrapperApplicationRef>
<Chain>
...
</Chain>
</Bundle>
</Wix>
下面代码为链接到网络上的一个许可协议页面的示例:
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Bundle>
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.HyperlinkLicense">
<bal:WixStandardBootstrapperApplication
LicenseUrl="http://example.com/license.html"
LogoFile="path\to\customlogo.png"
/>
</BootstrapperApplicationRef>
<Chain>
...
</Chain>
</Bundle>
</Wix>
当选择的WixStdBA主题使用链接来查看许可协议时,许可协议是可选的。当为WixStandardBootstrapperApplication/@LicenseUrl
提供空字符串时,链接文本和接受许可协议勾选框均不显示,它的感觉就像是安装未经授权。所以,如果你遇到如下提示错误:
The Windows Installer XML variable !(wix.WixStdbaLicenseUrl) is unknown
你可以设置WixStandardBootstrapperApplication/@LicenseUrl
的值,甚至提供一个空字符串。
修改WiX标准bootstrapper应用的品牌logo
WiX标准bootstrapper应用在用户界面左下角显示一个通用的logo。我们可以使用WixBalExtension提供的WixStandardBootstrapperApplication元素来更改显示的图像。以下示例了使用路径“path\to”下面的“customlogo.png”文件作为logo:
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Bundle>
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense">
<bal:WixStandardBootstrapperApplication
LicenseFile="path\to\license.rtf"
LogoFile="path\to\customlogo.png"
/>
</BootstrapperApplicationRef>
<Chain>
...
</Chain>
</Bundle>
</Wix>
而对于HyperlinkSidebarLicense的界面,会有两个logo可以配置,如下所示:
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Bundle>
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.HyperlinkSidebarLicense">
<bal:WixStandardBootstrapperApplication
LicenseUrl="License.htm"
LogoFile="path\to\customlogo.png" LogoSideFile="path\to\customsidelogo.png"
/>
</BootstrapperApplicationRef>
<Chain>
...
</Chain>
</Bundle>
</Wix>
定制WiX标准bootstrapper应用的界面布局
WiX标准bootstrapper应用含有一个预定义的用户界面布局。但我们还可以通过 WixBalExtension提供的WixStandardBootstrapperApplication元素来自定义布局。下面示例了使用“path\to”文件夹下的“customtheme.xml”文件配置界面:
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Bundle>
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense">
<bal:WixStandardBootstrapperApplication
LicenseFile="path\to\license.rtf"
ThemeFile="path\to\customtheme.xml"
/>
</BootstrapperApplicationRef>
<Chain>
...
</Chain>
</Bundle>
</Wix>
如果我们想为bootstrapper应用的进度页面添加Windows安装包操作情况消息数据显示,我们可以添加一个名为ExecuteProgressActionDataText的Text类型的控件。
<Page Name="Progress">
<Text X="11" Y="80" Width="-11" Height="30" FontId="2" DisablePrefix="yes">#(loc.ProgressHeader)</Text>
<Text X="11" Y="121" Width="70" Height="17" FontId="3" DisablePrefix="yes">#(loc.ProgressLabel)</Text>
<Text Name="OverallProgressPackageText" X="85" Y="121" Width="-11" Height="17" FontId="3" DisablePrefix="yes">#(loc.OverallProgressPackageText)</Text>
<Progressbar Name="OverallCalculatedProgressbar" X="11" Y="143" Width="-11" Height="15" />
<Text Name="ExecuteProgressActionDataText" X="11" Y="163" Width="-11" Height="17" FontId="3" DisablePrefix="yes" />
<Button Name="ProgressCancelButton" X="-11" Y="-11" Width="75" Height="23" TabStop="yes" FontId="0">#(loc.ProgressCancelButton)</Button>
</Page>
我们可以通过在主题文件内修改Windows元素的Width和Height属性值来改变bootstrapper应用的总体大小,还可以修改所有控件的大小或位置。
<Theme xmlns="http://wixtoolset.org/schemas/thmutil/2010">
<Window Width="485" Height="300" HexStyle="100a0000" FontId="0">#(loc.Caption)</Window>
你可以使用%WIX%\bin\
路径下的ThmViewer.exe来查看一个主题文件的内容,而并不需要建立一个捆绑包。
个人观点:ThmViewer.exe没啥特殊功能,就是看下主题文件结构,而主题文件本质上就是个xml格式文件,用文本编辑器就可以看。
使用WiX标准bootstrapper应用的变量
WiX标准bootstrapper应用提供了如下一组变量:
- WixBundleFileVersion - 获取捆绑包exe的文件版本
- WixStdBALanguageId - 获取WixStdBA用户界面上正在用的语言
译:奇葩史