Wix学习笔记(一)

Title:Wix学习笔记
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>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kagula086

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值