Windows Installer XML (WiX) 使用记录 (一)
来源:互联网 发布:非农数据图 编辑:程序博客网 时间:2024/05/16 01:13
被 Wix (Windows Installer XML) 折腾了很长的一段时间。为了确保以后不要被同样的问题折腾,决定把知识的都记录下来。
最简单的安装包。
1. 创建一个 Blank Solution,命名为 WixSample
2. 添加一个 C# 的 Console Application,命名为 HelloWorld,然后就是HelloWorld 的标准写法了。
using System;namespace HelloWorld{ class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } }}
3. 假设这个Console Application project 编译出来的 HelloWorld.exe 就是我们需要安装的程序。</span>
4. 制作安装包:
a. 创建一个 Wix 的 SetupProject.
b. 一个 Product.wxs 会被自动创建出来。
<?xml version="1.0" encoding="UTF-8"?><Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"><Product Id="*" Name="HelloWorldInstaller" Language="1033" Version="1.0.0.0" Manufacturer="" UpgradeCode="7bfca941-7a3a-4987-aaee-cba952487eff"><Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" /><MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." /><MediaTemplate /><Feature Id="ProductFeature" Title="HelloWorldInstaller" Level="1"><ComponentGroupRef Id="ProductComponents" /></Feature></Product><Fragment><Directory Id="TARGETDIR" Name="SourceDir"><Directory Id="ProgramFilesFolder"><Directory Id="INSTALLFOLDER" Name="HelloWorldInstaller" /></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> --></ComponentGroup></Fragment></Wix>
i. 如果尝试编译一下,是会有 error 的:
“TheProduct/@Manufacturer attribute's value cannot be an empty string. If a valueis not required, simply remove the entire attribute.”
有两个选择,要么把 Manufacturer="" 删掉;要么指定一下 Manufacturer,例如Manufacturer="The company name”
ii. 再编译一下,没有 error 了,但是有warning:
ICE71:The Media table has no entries.
需要把 “<MediaTemplate />” 改写成 “<MediaId="1" Cabinet="media1.cab" EmbedCab="yes" />”
老实说,这个具体什么含义我也不是很清楚,反正这样会压缩成一个单独的.msi 文件。当然,也可以选择压缩成多个.cab 文件。
如果想知道更多,可以参考文档:
http://wixtoolset.org/documentation/manual/v3/xsd/wix/media.html
iii. 继续编译,遇到另外一个 warning:
warningLGHT1079: The cabinet 'media1.cab' does not contain any files. If this installation contains no files, thiswarning can likely be safelyignored. Otherwise, please add files to the cabinet or remove it.
原因为 .msi文件里面没有任何东西。从现在开始,我们需要真正地编写安装包了。
c. 添加安装文件。
i. 添加输出项目。把 HelloWorldproject 添加到HelloWorldInstaller 的 Reference 里面
ii. 在名为 “ProductComponents”的 ComponentGroup 里面添加如下代码:
<ComponentId="HelloWorld.exe"Guid="42F0F0ED-CC76-474E-95DD-71B780BDF4D2"> <File Id="HelloWorld.exe"Source="$(var.HelloWorld.TargetDir)HelloWorld.exe" /> </Component>
这堆代码的意思是:
1. 创建一个id为HelloWorld.exe 的组件(Component),它的唯一标识符(Guid)为42F0F0ED-CC76-474E-95DD-71B780BDF4D2
2. 在这个组件里面包含了一个文件(File),它的id为HelloWorld.exe。也许有人会问那样Id不是冲突了么?
需要注意的是Component 和 File 是 父子级的关系,他们不再同一个作用域里面,所以不会冲突。但是要是在同一个Component 里面声明两个 id 为 HelloWorld.exe 的File,就会冲突了。
3. 代码 Source="$(var.HelloWorld.TargetDir)HelloWorld.exe" 是关键所在,它声明了在哪里可以找到这个HellowWorld.exe。
当在reference 里面添加 HelloWorld 项目的时候, 会自动生成变量 “var.HelloWorld.TargetDir” 。它的值是HelloWorld 项目的输出路径,通常要么是HelloWorld\bin\debug,或者HelloWorld\bin\Release。通过这个变量,就很容易找到需要安装的文件了。
iii. 再编译一下,无 error 无warning,大功告成。打开目录bin\debug(或者 bin\release) 会见到文件 HelloWorldInstaller.msi
d. 运行安装包
i. 双击安装包,会见到一个安装进度界面一闪而过。接着就没有然后了。。。
ii. 在控制面板的卸载程序里面,我们可以看到 HelloWorldInstaller 已经装上了。 目录C:\Program Files (x86)\HelloWorldInstaller 里面也有我们想安装的 HelloWorld.exe。实际上已经安装成功了。
iii. 在控制面板里面可以把 HelloWorldInstaller 彻底卸掉,完全不会留下痕迹。
e. OK,最简单的安装基本完成了,下一步是界面的问题。
完整源代码在 Github
https://github.com/IGabriel/WixSample/tree/A-Simplest-installer
- Windows Installer XML (WiX) 使用记录 (一)
- Windows Installer XML (WiX)
- Windows Installer XML (WiX) 使用记录 (二) -- 使用内置界面
- WIX 技巧-使用 MSBuild 和 Windows Installer XML 执行自动发布
- 【Wix】Windows Installer Error Code
- Wix 3.0支持Windows Installer 5.0
- Wix学习整理(3)——关于Windows Installer和MSI
- Wix学习整理(3)——关于Windows Installer和MSI
- Wix使用整理(一)
- Windows Installer XML 概述 (2)
- Windows Installer XML 概述 (3)
- Windows Installer XML 3.0
- WiX Wrapper Exe installer
- Wix学习(一)
- Wix打包系列(一)如何使用wix制作安装程序
- Wix打包系列(一)如何使用wix制作安装程序
- Wix打包系列(一)如何使用wix制作安装程序
- Wix打包系列(一)如何使用wix制作安装程序
- mysql中insert与select的嵌套使用
- 汇编语言单词缩写简介
- 一个小小清单,八月前完成-------Day67
- MPI调用C++程序
- POJ-1118-简单暴力题
- Windows Installer XML (WiX) 使用记录 (一)
- bupt暑假排位赛(1)
- poj_2935 Basic Wall Maze
- JspSmartUpload 实现下载
- 《Python基础教程》第20章学习笔记
- 【多级树形菜单-dialog自定义动画弹出方式-手势监听】dialog自定义动画
- Java集合源码学习(1)_架构
- httpd: Could not reliably determine the server's fully qualified domain name
- 【学习笔记】struts-tag与jstl的异同