最近研究用SD3和wix3开发程序, 网上关于wix3的资源及教程真是少的可怜,而且大部分是英文的。对于我这种高中英文120多,大学英文七八十的人来说真的很艰难。本文参考了园子里博友的文章,好了废话不多说,正文如下:
【wix 是什么】
Wix 是微软的开源的做 msi 安装包的工具。使用 xml 描述架构,经过编译链接后,得到 msi 安装包。整个过程跟写个程序差不多。
【用到的软件】
SharpDevelop: v3.0 c#IDE
Wix : 安装包制作工具
mallow : 编写 wix 文件时的辅助工具,tallow 的增强版,帮助生成文件列表
WixEdit : wix 文件编辑器
GuidGen : 微软的 guid 生成器,guid 在 wix 中占有重要位置,需要频繁用到
【开始】
SharpDevelop 中已经集成有 wix。我的版本是 v3.0,集成的 wix 是 3.0.4917.0 的。 wix3.0 已经发布,下载地址:http://sourceforge.net/projects/wix/files/。
在 SharpDevelop 中新建一个 setup 项目,选择【WixUI Mondo】——这个是 wix 内置的几个标准对话框项目之一。生成项目后,需要手工编辑默认的【files.wxs】和【setup.wxs】。
这2个文件怎么编辑呢?一堆的xml标签,毫无头绪啊~~呵呵,请看【典型结构】。
【典型结构】
wix 文件是标准的 xml 文件。任何文本编辑器都可以编辑。setup.wxs如下:
< Wix xmlns ="http://schemas.microsoft.com/wix/2006/wi" >
< Product Id ="*"
Name ="软件"
Language ="2052"
Version ="1.0.0.0"
Codepage ="936"
UpgradeCode ="825487A7-C3F9-44G5-B543-BB87BW239FBB"
Manufacturer ="公司" >
< Package Description ="#Description"
Comments ="Comments"
InstallerVersion ="200"
Compressed ="yes" />
<!--
Source media for the installation.
Specifies a single cab file to be embedded in the installer's .msi.
-->
< Media Id ="1" Cabinet ="contents.cab" EmbedCab ="yes" CompressionLevel ="high" />
<!-- 检测必备环境 -->
< PropertyRef Id ="NETFRAMEWORK20" />
< Condition Message ="您的计算机必须安装.NET Framework 2.0,否则本软件无法使用 ([NETFRAMEWORK20])" >
Installed OR NETFRAMEWORK20
Condition >
<!-- 检测必备环境 -->
<!-- Installation directory and files are defined in Files.wxs -->
< Directory Id ="TARGETDIR" Name ="SourceDir" >
<!-- 开始菜单 -->
< Directory Id ="ProgramMenuFolder" >
< Directory Id ="ShortcutMenuFolder" Name ="软件" />
Directory >
<!-- 开始菜单结束 -->
<!-- 桌面快捷方式 -->
< Directory Id ="DesktopFolder" Name ="Desktop" >
< Component Id ="DesktopSpider" Guid ="aede1637-df5a-4c41-94b6-f077d03e5372" >
< RegistryKey Root ="HKCU" Key ="Software\AAA\desktop" >
< RegistryValue Value ="SPIDERClient" Type ="string" KeyPath ="yes" />
RegistryKey >
< Shortcut Id ="shortcut.desk" Directory ="DesktopFolder" Name ="软件" Target ="[INSTALLDIR]ruanjian.exe" WorkingDirectory ="INSTALLDIR" IconIndex ="0" />
Component >
Directory >
<!-- 桌面快捷方式结束 -->
Directory >
<!-- Targetdir 结束 -->
<!-- 开始菜单设置 -->
< DirectoryRef Id ="ShortcutMenuFolder" >
< Component Id ="ApplicationShortcut" Guid ="C919F5ED-D2B3-42E8-9F7C-63269274FE79" >
< Shortcut Id ="ApplicationStartMenuShortcut" Name ="软件" Target ="[INSTALLDIR]ruanjian.exe" WorkingDirectory ="INSTALLDIR" />
< Shortcut Id ="UninstallProduct" Name ="卸载" Target ="[System64Folder]msiexec.exe" Arguments ="/x [ProductCode]" />
< RemoveFolder Id ="ShortcutMenuFolder" On ="uninstall" />
< RegistryValue Root ="HKCU" Key ="Software\软件" Name ="installed" Type ="integer" KeyPath ="yes" Value ="1" />
Component >
DirectoryRef >
<!-- 开始菜单 -->
< Feature Id ="Complete"
Title ="软件"
Description ="**软件"
Level ="1"
ConfigurableDirectory ="INSTALLDIR" >
< ComponentRef Id ="ExecutableFile" />
< ComponentRef Id ="MyComponent" />
< ComponentRef Id ="ApplicationShortcut" />
< ComponentRef Id ="DesktopSpider" />
Feature >
<!--
Using the Wix UI library
WixUI_Mondo includes the full set of dialogs:
welcome
license agreement
setup type (typical, custom, and complete)
feature customization
directory browse
disk cost.
Maintenance-mode dialogs are also included.
Use WixUI_Mondo when you have some of your product's features
are not installed by default and there is a meaningful
difference between typical and complete installs
-->
< UIRef Id ="WixUI_Mondo" />
Product >
Wix >
需要注意到是:
所有的 GUID 都要自己生成
“公司”、“软件”换成自己的
标签中表示了需要打包的文件,这部分内容如果手工一个一个的写是很烦人的。所以可以借助上面【软件】中提到的 mallow 协助。
以下是 files.wxs基本内容
< Wix xmlns ="http://schemas.microsoft.com/wix/2006/wi" >
< Fragment >
< DirectoryRef Id ="TARGETDIR" >
< Directory Id ="ProgramFilesFolder" Name ="PFiles" >
< Directory Id ="INSTALLDIR" Name ="软件名" >
< Component Id ="MyComponent" Guid ="5432EBE2-66E1-48F0-A0BF-A256479B168E" DiskId ="1" >
< File Id ="LicenseFile" Name ="license.rtf" Source ="license.rtf" />
Component >
< Component Id ='ExecutableFile' DiskId ='1' Guid ='11111111-1111-1111-1111-111111111192' >
< File Id ='ruanjian_exe' Name ='ruanjian.exe' Source ="目录/ruanjian.exe" />
Component >
Directory >
Directory >
DirectoryRef >
Fragment >
Wix >
【本地化】
我们都习惯了安装程序有个向导,一步一步的进行。不过默认生成的向导——比如我用的这个【WxUI Mondo】——界面文字是英文的,我们当然希望是中文的。wix 提供了中文的资源文件。在使用light.exe链接时,增加命令行参数 -loc xxx.wxl 即可。不过在 SharpDevelop 中要怎么做呢?
注意:以下内容摘自博友博客,本博客内上面的代码已经修改。
在下一步之前,要先修改 setup.wxs 中的几个地方,否则是不能支持中文的。
修改前 | 修改后 |
---|---|
<?xml version="1.0"?> | <?xml version="1.0" encoding="utf-8"?> |
Language="1033" | Language="2052" |
Codepage="936" |
我们可以下载 3.0 的源码包,解开后,可以在源码目录下的 src\ext\UIExtension\wixlib 得到 3.0 的 wixui_en-us.wxl 英文语言文件;再下载 2.0 的 wixui_zh-cn.wxl 中文语言包,参照 wixui_en-us.wxl 稍微修改一下:
3.0 | 2.0 | 修改后 |
---|---|---|
http://schemas.microsoft.com/wix/2006/localization"> | http://schemas.microsoft.com/wix/2006/localization"> | |
&Back | 上一步(&B) | 上一步(&B) |
…… | …… | 所有的 overridalbe 都要加上 |
然后将文件 wixui_zh-cn.wxl 加入到 SharpDevelop 的 setup 项目中去,文件的【Build Action】选择【EmbeddedResource】即可。
不过编译的时候还会报错,因为 wix 3.0 和 2.0 的结构不一样,报错的原因是有几个地方 3.0 新增的,修改好 wixui_zh-cn.wxl 就行了。中文翻译可以自己写。
修改前 | 修改后 |
---|---|
[ProductName] 安装程序 | |
目录无效 | |
信息图标 | |
WixUI_Ico_Info | |
禁止通过修复丢失和损坏的文件、快捷方式和注册表项,修复最新安装中的错误。 | |
禁止将 [ProductName] 从您的计算机中删除。 | |
新文件夹 |
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-609333/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/12639172/viewspace-609333/