【发布时间】:2011-01-11 13:41:59
【问题描述】:
我正在使用 WiX 工具来创建安装程序。
在创建“开始”菜单和桌面快捷方式时,我需要安装程序将其设为可选。
类似于:[ ] 你想创建一个开始菜单快捷方式吗?
这可能吗?
【问题讨论】:
标签: wix windows-installer shortcut
我正在使用 WiX 工具来创建安装程序。
在创建“开始”菜单和桌面快捷方式时,我需要安装程序将其设为可选。
类似于:[ ] 你想创建一个开始菜单快捷方式吗?
这可能吗?
【问题讨论】:
标签: wix windows-installer shortcut
是的,这绝对是可能的。总体思路是让快捷组件以某个属性为条件,然后自定义您的 UI 以将复选框连接到该属性。
所有这些都在Wix Tutorial 中进行了描述(尽管不是针对您的具体示例),这是一篇有见地的读物。但这里有一些针对您的案例的更具体的代码示例:
创建一个可以将复选框连接到的属性。在您的 .wxs 文件中,添加 Property 以将值存储在其中。
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product ...>
<Property Id="INSTALLSHORTCUT" />
</Product>
</Wix>
将Condition 添加到安装快捷方式的组件中,因此它取决于您的新INSTALLSHORTCUT 属性的值。
<Component Id="ProgramFilesShortcut" Guid="*">
<Condition>INSTALLSHORTCUT</Condition>
<Shortcut Id="ProductShortcut" ... />
</Component>
您需要自定义一个对话框以向 UI 添加一个复选框并将其连接到 INSTALLSHORTCUT 属性。我不会在这里详细介绍,但是这里有一个很好的教程:User Interface Revisited
您需要下载 wix 源代码树以获取您正在使用的 UI 的 .wxs 文件。例如,要将复选框添加到WixUI_InstallDir UI 中的InstallDir 对话框,您需要下载WixUI_InstallDir.wxs 和InstallDirDlg.wxs。将它们添加到您的 Wix 项目并重命名它们(例如,Custom_InstallDir.wxs 和 Custom_InstallDirDlg.wxs)。
编辑Custom_InstallDirDlg.wxs 以添加您的复选框。也给<Dialog> 一个新的Id:
<Wix ...>
<Fragment>
<UI>
<Dialog Id="InstallDirAndOptionalShortcutDlg" ...>
<Control Id="InstallShortcutCheckbox" Type="CheckBox"
X="20" Y="140" Width="200" Height="17"
Property="INSTALLSHORTCUT" CheckBoxValue="1"
Text="Do you want to create a start menu shortcut?" />
</Dialog>
</UI>
</Fragment>
</Wix>
编辑Custom_InstallDir.wxs 以使用自定义的InstallDirAndOptionalShortcut 对话框:
<Wix ...>
<Fragment>
<UI Id="Custom_InstallDir">
** Search & Replace all "InstallDirDlg" with "InstallDirAndOptionalShortcut" **
</UI>
</Fragment>
</Wix>
最后,在主 .wxs 文件中引用您的自定义 UI:
<Wix ...>
...
<UIRef Id="Custom_InstallDir" />
...
</Wix>
【讨论】:
<Property Id="INSTALLSHORTCUT" Secure="yes"/> Secure 必须设置为 yes 才能通过条件访问此属性。
Directory 属性添加到@987654345 @,例如<Component ... Directory="APPLICATIONDIR"> (2) <ShortCut> 需要这些属性:<Shortcut ... Advertise="no" Target="[#MyApp.exe]" />(注意:它是“目标”中的文件 ID)(3) 添加一个虚拟注册表像<RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="desktop icon = 1" KeyPath="yes" /> 这样的组件入口以避免WiX 错误。 (4) 查看 Felix 的评论
在复选框单击事件或下一个按钮单击时,您可以调用自定义操作来创建快捷方式。
【讨论】: