昨天添加完UI后 ,我们Installer终于可以和用户交互了,虽然很简单,但总算有个好的开头...可是安装完之后呢?额...我们的产品到哪里启动啊?!太大意了,居然没有给程序做快捷方式!总不能每次让使用者从C:\Program Files\WixProject\下启动吧~
那在WiX中怎么创建呢?
代码
<?
xml version="1.0" encoding="UTF-8"
?>
<
Wix
xmlns
="http://schemas.microsoft.com/wix/2006/wi"
>
<
Product
Id
="e6ecf2a7-b03c-4b3f-ace8-6179ab62e4c7"
Name
="WixProject"
Language
="1033"
Version
="1.0.0.0"
Manufacturer
="WixProject"
UpgradeCode
="b3d503b8-4f21-4116-8562-6ff1e0e16a28"
>
<
Package
InstallerVersion
="200"
Compressed
="yes"
/>
<
Media
Id
="1"
Cabinet
="media1.cab"
EmbedCab
="yes"
/>
<
Directory
Id
="TARGETDIR"
Name
="SourceDir"
>
<
Directory
Id
="ProgramFilesFolder"
>
<
Directory
Id
="INSTALLLOCATION"
Name
="WixProject"
>
<
Component
Id
="Com.ProductComponent"
Guid
="266b1212-45bf-4b65-a31a-29c3bdc43e20"
>
<
File
Id
="WindowsFormsApplication.exe"
Source
="$(var.SolutionDir)\WindowsFormsApplication\$(var.OutDir)\WindowsFormsApplication.exe"
KeyPath
="yes"
>
<
Shortcut
Id
="WindowsFormsApplicationStartmenu"
Directory
="ProgramMenuDir"
Name
="Windows Forms Application"
WorkingDirectory
='INSTALLDIR'
Icon
="WindowsFormsApplicationIcon.exe"
IconIndex
="0"
Advertise
="yes"
/>
<
Shortcut
Id
="WindowsFormsApplicationIconDesktop"
Directory
="DesktopFolder"
Name
="Windows Forms Application"
WorkingDirectory
='INSTALLDIR'
Icon
="WindowsFormsApplicationIcon.exe"
IconIndex
="0"
Advertise
="yes"
/>
</
File
>
</
Component
>
</
Directory
>
</
Directory
>
<
Directory
Id
="ProgramMenuFolder"
Name
="Programs"
>
<
Directory
Id
="ProgramMenuDir"
Name
="Windows Forms Application"
>
<
Component
Id
="Com.ProgramMenuDir"
Guid
="0194D405-F08A-4a86-AA83-75E9EB336BBE"
>
<
RemoveFolder
Id
='ProgramMenuDir'
On
='uninstall'
/>
<
RegistryValue
Id
='regValue'
Root
='HKCU'
Type
='string'
Key
='Software\[Manufacturer]\[ProductName]'
Name
='Location'
Value
='[INSTALLLOCATION]'
/>
</
Component
>
</
Directory
>
</
Directory
>
<
Component
Id
="Com.Reg"
Guid
="E5619341-E3B8-4513-970B-A9924DE3EE26"
>
<
RegistryKey
Root
="HKLM"
Key
="Software\[Manufacturer]\[ProductName]"
Action
="createAndRemoveOnUninstall"
>
<
RegistryValue
Type
="string"
Name
="Product"
Value
="[ProductName]"
KeyPath
="yes"
/>
<
RegistryValue
Type
="string"
Name
="Version"
Value
="[ProductVersion]"
/>
<
RegistryValue
Type
="string"
Name
="Location"
Value
="[INSTALLLOCATION]"
/>
<
RegistryValue
Type
="string"
Name
="Language"
Value
="[ProductLanguage]"
/>
</
RegistryKey
>
</
Component
>
<
Directory
Id
="DesktopFolder"
Name
="Desktop"
/>
</
Directory
>
<
Feature
Id
="Product"
Title
="Windows Form sApplication"
Level
="1"
>
<
ComponentRef
Id
="Com.ProductComponent"
/>
</
Feature
>
<
Feature
Id
="Others"
Title
="Shortcuts,Registry"
Level
="1"
>
<
ComponentRef
Id
="Com.ProgramMenuDir"
/>
<
ComponentRef
Id
="Com.Reg"
/>
</
Feature
>
<
Icon
Id
="WindowsFormsApplicationIcon.exe"
SourceFile
="$(var.SolutionDir)\WindowsFormsApplication\$(var.OutDir)\WindowsFormsApplication.exe"
/>
<
UIRef
Id
="WixUI_FeatureTree"
/>
</
Product
>
</
Wix
>
有点儿多且乱哈,没关系,我们一步一步来看~先看快捷方式.
代码
<
Shortcut
Id
="WindowsFormsApplicationStartmenu"
Directory
="ProgramMenuDir"
Name
="Windows Forms Application"
WorkingDirectory
='INSTALLDIR'
Icon
="WindowsFormsApplicationIcon.exe"
IconIndex
="0"
Advertise
="yes"
/>
<
Shortcut
Id
="WindowsFormsApplicationIconDesktop"
Directory
="DesktopFolder"
Name
="Windows Forms Application"
WorkingDirectory
='INSTALLDIR'
Icon
="WindowsFormsApplicationIcon.exe"
IconIndex
="0"
Advertise
="yes"
/>
Shortcut 1) 这里建立了两个位置的快捷方式,一个在"所有程序"文件夹里,一个在桌面~
2) 有两个属性需要注意,一个是"Directory":两个值"ProgramMenuDir"和"DesktopFolder"分别在后面定义的
代码
<
Directory
Id
="ProgramMenuFolder"
Name
="Programs"
>
<
Directory
Id
="ProgramMenuDir"
Name
="Windows Forms Application"
>
...
</
Directory
>
</
Directory
>
<
Directory
Id
="DesktopFolder"
Name
="Desktop"
/>
另一个是"Icon",同样是引用了一个具体的量
<
Icon
Id
="WindowsFormsApplicationIcon.exe"
SourceFile
="$(var.SolutionDir)\WindowsFormsApplication\$(var.OutDir)\WindowsFormsApplication.exe"
/>
或许你注意到了吧,这个定义Icon的Id值有点儿特别,带有个"扩展名(.exe)".对咯,是和具体的SourceFile 扩展名一致的,这是WiX的定义规范~你试着删除掉~
P.S.,如果你安装完毕后看不到ICON...那很可能你的应用程序没包含吧~
除了快捷方式,将产品信息写入注册表也是必须做的(主要是给其他程序查询自己提供方便,当然卸载的时候一定记着清理掉...不然就"流氓"了
代码
<
Component
Id
="Com.ProgramMenuDir"
Guid
="0194D405-F08A-4a86-AA83-75E9EB336BBE"
>
<
RemoveFolder
Id
='ProgramMenuDir'
On
='uninstall'
/>
<
RegistryValue
Id
='regValue'
Root
='HKCU'
Type
='string'
Key
='Software\[Manufacturer]\[ProductName]'
Name
='Location'
Value
='[INSTALLLOCATION]'
/>
</
Component
>
......
<
Component
Id
="Com.Reg"
Guid
="E5619341-E3B8-4513-970B-A9924DE3EE26"
>
<
RegistryKey
Root
="HKLM"
Key
="Software\[Manufacturer]\[ProductName]"
Action
="createAndRemoveOnUninstall"
>
<
RegistryValue
Type
="string"
Name
="Product"
Value
="[ProductName]"
KeyPath
="yes"
/>
<
RegistryValue
Type
="string"
Name
="Version"
Value
="1.0.0.0"
/>
<
RegistryValue
Type
="string"
Name
="Location"
Value
="[INSTALLLOCATION]"
/>
<
RegistryValue
Type
="string"
Name
="Language"
Value
="[ProductLanguage]"
/>
</
RegistryKey
>
</
Component
>
说明 1) RemoveFolder/RemoveFile,顾名思义删除文件夹和文件的,你可以选择什么时候做这些操作,这里是在"卸载"的时候,把给快捷方式创建的folder移除掉(默认是必须有这个的...),在HKCU中写入Registry也是必须的,把"Root"设置成"HKLM"试试~
2) 接下来几行都是写入HKLM注册表的~先建立主Key,在写入Key/Value值.在方括号("[]")中的都是MSI的"Property(属性)",都是再其他地方定义过的,找找看~ ^^" Action也值得试玩一下,还有移掉"Keypath"~
对了,我们还增加了一个Feature项,结合"WixUI_FeatureTree",看看有什么不一样的地方?
代码
<
Feature
Id
="Product"
Title
="Windows Form sApplication"
Level
="1"
>
<
ComponentRef
Id
="Com.ProductComponent"
/>
</
Feature
>
<
Feature
Id
="Others"
Title
="Shortcuts,Registry"
Level
="1"
>
<
ComponentRef
Id
="Com.ProgramMenuDir"
/>
<
ComponentRef
Id
="Com.Reg"
/>
</
Feature
>
......
<
UIRef
Id
="WixUI_FeatureTree"
/>
好了,这下用户可以很方便的启动我们的程序了!
开始菜单
桌面
不知道有人试过没,把"Compressed"或者"EmbedCab"设置成"no",编译后有啥效果? Compressed="no",需要安装的文件将不会被打包在MSI里,而是放在WixProject目录中(可以随便替换被安装文件~) EmbedCab="no"