WIX是开源的安装包制作工具,基于XML编译安装包,由于它提供命令行的方式编译,因此可很好的融入到开发项目的持续集成中,因此是不想用盗版也不想花钱的开发团队的最好武器。
WIX脚本
静默调用控制台程序
- 如果安装过程需要调用外部控制台程序,可屏蔽安装过程中出现的控制台窗口,如例:
<
CustomAction
Id
="service_start_cmd"
Property
="QtExecCmdLine"
Value
=""sc.exe" start SERVICE_NAME"
/>
< CustomAction Id ="service_start" BinaryKey ="WixCA" DllEntry ="CAQuietExec" Execute ="immediate" Return ="check" />
< InstallExecuteSequence >
< Custom Action ="service_start_cmd" After ="modify_config" Overridable ="yes" > NOT Installed </ Custom >
< Custom Action ="service_start" After ="service_start_cmd" Overridable ="yes" > NOT Installed </ Custom >
</ InstallExecuteSequence >
< CustomAction Id ="service_start" BinaryKey ="WixCA" DllEntry ="CAQuietExec" Execute ="immediate" Return ="check" />
< InstallExecuteSequence >
< Custom Action ="service_start_cmd" After ="modify_config" Overridable ="yes" > NOT Installed </ Custom >
< Custom Action ="service_start" After ="service_start_cmd" Overridable ="yes" > NOT Installed </ Custom >
</ InstallExecuteSequence >
- 注意:传给"QtExecCmdLine"的值中,命令行里程序名必须用引号包围,如上例中的"sc.exe"
加入系统启动项目
<
Directory
Id
="ProgramMenuFolder"
Name
="ProgramMenuFolder"
>
< Directory Id ="ProgramMenuFolderGTCA" Name ="GTCA" >
< Component Id ="ProgramMenuGTCA" Guid ="51F97418-ABF1-43B7-BB4C-2E77437FC7F1" >
< RegistryKey Root ="HKCU" Key ="Software\GTCA\EAF\Program" >
< RegistryValue Value ="EAFClient" Type ="string" KeyPath ="yes" />
</ RegistryKey >
< Shortcut Id ="shortcut.prog" Directory ="ProgramMenuFolderGTCA" Name ="智能客户平台"
Target ="EAFVersiondir\EAFMain.exe" WorkingDirectory ="EAFVersiondir"
Icon ="EAFMain.exe" IconIndex ="0" />
< RemoveFolder Id ="RemoveShorcutFolder" On ="uninstall" />
</ Component >
</ Directory >
</ Directory >
< Directory Id ="ProgramMenuFolderGTCA" Name ="GTCA" >
< Component Id ="ProgramMenuGTCA" Guid ="51F97418-ABF1-43B7-BB4C-2E77437FC7F1" >
< RegistryKey Root ="HKCU" Key ="Software\GTCA\EAF\Program" >
< RegistryValue Value ="EAFClient" Type ="string" KeyPath ="yes" />
</ RegistryKey >
< Shortcut Id ="shortcut.prog" Directory ="ProgramMenuFolderGTCA" Name ="智能客户平台"
Target ="EAFVersiondir\EAFMain.exe" WorkingDirectory ="EAFVersiondir"
Icon ="EAFMain.exe" IconIndex ="0" />
< RemoveFolder Id ="RemoveShorcutFolder" On ="uninstall" />
</ Component >
</ Directory >
</ Directory >
加入桌面快捷方式
<
Directory
Id
="DesktopFolder"
Name
="Desktop"
>
< Component Id ="DesktopGTCA" Guid ="aede1637-df5a-4c41-94b6-f077d03e5372" >
< RegistryKey Root ="HKCU" Key ="Software\AAA\desktop" >
< RegistryValue Value ="EAFClient" Type ="string" KeyPath ="yes" />
</ RegistryKey >
< Shortcut Id ="shortcut.desk" Directory ="DesktopFolder" Name ="智能客户端" Target ="main\main.exe" WorkingDirectory ="main" Icon ="EAFMain.exe" IconIndex ="0" />
</ Component >
</ Directory >
< Component Id ="DesktopGTCA" Guid ="aede1637-df5a-4c41-94b6-f077d03e5372" >
< RegistryKey Root ="HKCU" Key ="Software\AAA\desktop" >
< RegistryValue Value ="EAFClient" Type ="string" KeyPath ="yes" />
</ RegistryKey >
< Shortcut Id ="shortcut.desk" Directory ="DesktopFolder" Name ="智能客户端" Target ="main\main.exe" WorkingDirectory ="main" Icon ="EAFMain.exe" IconIndex ="0" />
</ Component >
</ Directory >
加入VC运行库
<
Directory
Id
="TARGETDIR"
Name
="SourceDir"
>
< Merge Id ="Microsoft_VC80_CRT_x86"
SourceFile ="$(var.GTSetupLibraryPath)\Microsoft_VC80_CRT_x86.msm" DiskId ="1" Language ="2052" />
< Merge Id ="policy_8_0_Microsoft_VC80_CRT_x86"
SourceFile ="$(var.GTSetupLibraryPath)\policy_8_0_Microsoft_VC80_CRT_x86.msm" DiskId ="1" Language ="1033" />
</ Directory >
< Feature Id ="main" Title ="main" Level ="1" >
< MergeRef Id ="Microsoft_VC80_CRT_x86" />
< MergeRef Id ="policy_8_0_Microsoft_VC80_CRT_x86" />
</ Feature >
< Merge Id ="Microsoft_VC80_CRT_x86"
SourceFile ="$(var.GTSetupLibraryPath)\Microsoft_VC80_CRT_x86.msm" DiskId ="1" Language ="2052" />
< Merge Id ="policy_8_0_Microsoft_VC80_CRT_x86"
SourceFile ="$(var.GTSetupLibraryPath)\policy_8_0_Microsoft_VC80_CRT_x86.msm" DiskId ="1" Language ="1033" />
</ Directory >
< Feature Id ="main" Title ="main" Level ="1" >
< MergeRef Id ="Microsoft_VC80_CRT_x86" />
< MergeRef Id ="policy_8_0_Microsoft_VC80_CRT_x86" />
</ Feature >
设置文件共享
需要引用UtilExtension
<!--
将安装目录共享给EveryOne
-->
< Component Id ="MyFileShare" Guid ="6f051579-2950-42e3-9381-2f538ae1de12" >
< CreateFolder />
< util:User Id ="Everyone" Name ="Everyone" />
< util:FileShare Id ="ShareRoot" Name ="[INSTALLDIR]" >
< util:FileSharePermission GenericAll ="yes" User ="Everyone" Read ="yes" />
</ util:FileShare >
</ Component >
< Component Id ="MyFileShare" Guid ="6f051579-2950-42e3-9381-2f538ae1de12" >
< CreateFolder />
< util:User Id ="Everyone" Name ="Everyone" />
< util:FileShare Id ="ShareRoot" Name ="[INSTALLDIR]" >
< util:FileSharePermission GenericAll ="yes" User ="Everyone" Read ="yes" />
</ util:FileShare >
</ Component >
创建系统服务
- 与要运行的EXE程序的同一Component下加入
<
ServiceInstall
Id
="service_install"
Name
="SERVICE_NAME"
DisplayName
="GTCA Server"
Start
="auto"
ErrorControl
="normal"
Type
="ownProcess"
/>
< ServiceControl Id ="service_control" Name ="SERVICE_NAME" Start ="install" Stop ="uninstall" Remove ="uninstall" />
< ServiceControl Id ="service_control" Name ="SERVICE_NAME" Start ="install" Stop ="uninstall" Remove ="uninstall" />
- 要运行的EXE程序必须设置KeyPath="yes"
- 如果出现卸载时无法停止并删除服务的情况,需要为该Component重新生成GUID
补丁与升级
制作补丁(小型升级)
- 程序主版本号不变的情况下进行升级即小型升级
- 前提条件
- 前后两版本一定要ProductCode和UpgrageCode一致
- 前后两版本主版本号一致
- 编译的机器上未安装该程序的任何版本
- 步骤
- 编译得到前后两个版本msi文件
- 编制补丁的wxs文件patch.wxs
- 编制Msbuild项目文件patch.proj,其中动作顺序为
- 将前后两个版本安装到临时目录
- 编译wsx得到pcp文件
- 调用msimsp生成msp文件
安装补丁
- 直接双击运行msp文件
- 命令行
msiexec
/
p
patch
.
msp REINSTALL
=
[Feature list] REINSTALLMODE
=
omus
- VB脚本
DIM
Installer
ON ERROR RESUME NEXT
set Installer = CreateObject ( " WindowsInstaller.Installer " )
Installer.ApplyPatch " http://server/share/patch.msp " , "" , 0 , " REINSTALL=ALL REINSTALLMODE=omus "
set Installer = Nothing
将补丁应用到MSI
ON ERROR RESUME NEXT
set Installer = CreateObject ( " WindowsInstaller.Installer " )
Installer.ApplyPatch " http://server/share/patch.msp " , "" , 0 , " REINSTALL=ALL REINSTALLMODE=omus "
set Installer = Nothing
msiexec
/
a [
path
to administrative image
.
msi file]
/
p
patch
.
msp
部署程序集
- 一定要强签名
- 将程序集注册到GCA
- 程序修改后,一定修改版本号
- 要将程序集注册到GCA,WXS脚本如例(千万不要把Name写错,否则编译通过安装成功但注册不上)
< Component Id ="AxMAVClientLib.dll" Guid ="YOUR-NEW-GUID-HERE" >
< File Id ="AxMAVClientLib.dll" Name ="AxMAVClientLib.dll" KeyPath ="yes"
Assembly =".net" ProcessorArchitecture ="msil" Source ="AxMAVClientLib.dll" />
</ Component >
参考和引用
- WIX How To http://www.dalun.com/wix/06.10.2005.htm
- WIX Q&A http://msdn.microsoft.com/chats/transcripts/windows/windows_110904a.aspx
- WIX Localization Project http://www.tramontana.co.hu/wix/loc/index.php