Wix有五个内置的界面模版:
WixUI_Advanced
WixUI_FeatureTree
WixUI_Minimal
这里介绍一下常用的WixUI_Minimal, WixUI_InstallDir 和 WixUI_Mondo。它们基本上可以解决九成以上的问题了。
如果想要更多的信息可以到下列地址查看:
http://wixtoolset.org/documentation/manual/v3/wixui/wixui_dialog_library.html
使用内置界面之前 ,需要添加引用 WixUIExtenstion.dll (AddUIExtension.png)
-
WixUI_Minimal
添加如下代码即可 :
<UIRef Id="WixUI_Minimal"/>
编译后出来一个极其简单的安装界面,勾选“Iaccept the term in the license agreement”即可点击install 安装。
-
WixUI_InstallDir
与 WixUI_Minimal 相比,多了一个页面。
使用方法差不多,添加如下代码:
<UIRef Id="WixUI_InstallDir"/>
还需要指定一个built -in 的变量
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
-
WixUI_Mondo
这个模版可以让用户选择安装那些组件,如图:
代码如下:
<UIRef Id="WixUI_Mondo"/>
这个模板有个问题,就是没有了安装路径的界面。不过它提供了为组件选择路径的功能,只需要在Feature 上指定 ConfigurableDirectory 属性。代码如下:
<Feature Id="ProductFeature" Title="HelloWorldInstaller" Level="1" ConfigurableDirectory="INSTALLFOLDER"> <ComponentGroupRef Id="ProductComponents" /> </Feature>
效果如图:
如果有好几个组件,并且希望它们都安装在同一个目录里面呢?我们可以定义多个Feature,然后合并到同一个Feature 下面。可以这样做:
先添加两个项目,CPPConsole 和 CSharpForm
然后新添加的两个项目加入安装包中
<Fragment> <ComponentGroup Id="HelloWroldComponents" Directory="INSTALLFOLDER"> <Component Id="HelloWorld.exe" Guid="42F0F0ED-CC76-474E-95DD-71B780BDF4D2"> <File Id="HelloWorld.exe" Source="$(var.HelloWorld.TargetDir)HelloWorld.exe" /> </Component> </ComponentGroup> <ComponentGroup Id="CPPConsoleComponents" Directory="INSTALLFOLDER"> <Component Id="CPPConsole.exe" Guid="36F4C572-A95E-436D-8A4B-0F08B9AADF6D"> <File Id="CPPConsole.exe" Source="$(var.CPPConsole.TargetDir)CPPConsole.exe" /> </Component> </ComponentGroup> <ComponentGroup Id="CSharpFormComponents" Directory="INSTALLFOLDER"> <Component Id="CSharpForm.exe" Guid="85A7912E-CE9D-4AE1-8AB2-C401779C6EB5"> <File Id="CSharpForm.exe" Source="$(var.CSharpForm.TargetDir)CSharpForm.exe" /> </Component> </ComponentGroup> </Fragment>
定制 Features
<Feature Id="ProductFeature" Title="TestInstaller" Level="1" ConfigurableDirectory="INSTALLFOLDER" Display="expand"> <Feature Id="HelloWorldFeature" Title="Hello World" Level="1"> <ComponentGroupRef Id="HelloWroldComponents" /> </Feature> <Feature Id="CPPConsoleFeature" Title="CPP consoloe" Level="1"> <ComponentGroupRef Id="CPPConsoleComponents" /> </Feature> <Feature Id="CSharpFormFeature" Title="C# form" Level="1"> <ComponentGroupRef Id="CSharpFormComponents" /> </Feature> </Feature>
效果如图:
上述代码可以从这里获得:
https://github.com/IGabriel/WixSample/tree/Built-in-UI
还有两个个经常遇到的问题:
如何更换License agreement?
通常默认的license agreement 都不是你想要的,可以选择自己的 license agreement。首先准备一份license.rft 文件,里面是自己写的许可协议。接着把它放到某个地方(为了简单,放到项目的根目录)。然后添加如下代码:
就可以看到license agreement 已经替换了。
如何更换背景图片?
有几个built-in 的变量可以用于自定义背景图:
变量名 | 描述 | 规格 |
---|---|---|
WixUIBannerBmp | 安装界面最上方的横幅 | 493 × 58 |
WixUIDialogBmp | 整个安装包的背景图片 | 493 × 312 |
WixUIInfoIco | 取消或者错误弹出对话框的图标 | 32 × 32 |
WixUINewIco | 选择路径页面的“新建”按钮图标 | 16 × 16 |
WixUIUpIco | 选择路径页面的“向上”按钮图标 | 16 × 16 |