Date: 2015-05-18
Environment:
VS2013Update4、Win7SP1、WinXPSP3、WiX Toolset v3.9 R2
内容简介:
学习使用Wix来打安装包。
最简单的安装程序(共三步)。
为testWix添加SetupProject1安装项目。
第一步:
打开现有的C++项目,[Add New Project]->[Windows Installer XAML]->[Setup Project]添加安装项目。
第二步:打开Product.wxs源文件,并修改。
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<!--Product节点Name属性指定了控制面板卸载程序列表里的名字-->
<Product Id="*" Name="SetupProject1" Language="1033" Version="1.0.0.0" Manufacturer="kagula" UpgradeCode="7b8f5cf7-d71f-4140-9616-9f5088c4e45b">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SetupProject1" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="SetupProject1" /><!--Name属性指定了目标安装目录-->
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<!-- <Component Id="ProductComponent"> -->
<!-- TODO: Insert files, registry keys, and other resources here. -->
<!-- </Component> -->
<Component Id="ProductComponent" Guid="B5F0C012-49D6-4C63-AFCA-0CE6C24C6D7D">
<File Id="HelloWorld" Source="../Debug/testWiX.exe" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
第三步:
编译并运行,即可。
输出目录在.....\testWiX\SetupProject1\bin\Debug
Note “testWiX” is Solution name,“SetupProject1” is set project name.
---------------------------------------------------------------------------------------------------------------------------------
使用预定义变量(三步)
第一步:为安装工程(SetupProject1)添加程序项目(testWiX)引用。
[SetupProject1]->[References]->[Add Reference]->[Projects]->添加testWiX项目。
第二步:Product.wxs文件下面的源码
<File Id="HelloWorld" Source="../Debug/testWiX.exe" />
替换为
<File Id="HelloWorld" Source="../$(var.testWiX.Configuration)/$(var.testWiX.TargetFileName)" />
第三步:重新编译即可。
参考资料[4]查看其它预定义变量,进一步阅读参数资料[3]。
---------------------------------------------------------------------------------------------------------------------------------
开始菜单快捷方式(三步)
第一步:编译Product.wxs文件。
在Fragment的Id为TARGETDIR的Directory子节点中插入下面的节点,指示开始菜单下要有个testWiX文件夹。
<Directory Id="ProgramMenuFolder"><!--Directory节点Id属性[1]指示这是个什么目录?这里指的是开始菜单(目录)[2]用来Reference-->
<Directory Id="ApplicationProgramsFolder" Name="testWiX"/><!--Name属性指示,开始菜单的什么子文件夹》-->
</Directory>
第二步:
在什么位置,新建什么名字的Shortcut。
添加下面的Fragment。
<Fragment>
<DirectoryRef Id="ApplicationProgramsFolder"><!--Id属性为ApplicationProgramsFolder同上面一致-->
<!--a <Component> element to specify an atomic unit of installation...-->
<Component Id="ApplicationShortcut" Guid="{6EC4A3C2-147D-41C4-BC14-814EEAC48C37}">
<!--Shortcut节点的Name属性,指示快捷键的名称-->
<Shortcut Id="ApplicationStartMenuShortcut"
Name="testWiX"
Description="My Application Description"
Target="[INSTALLFOLDER]$(var.testWiX.TargetFileName)"
WorkingDirectory="INSTALLFOLDER"/>
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/><!--Id属性为ApplicationProgramsFolder同上面一致-->
<RegistryValue Root="HKCU" Key="Software\Microsoft\testWiX" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>
</Fragment>