"创建快捷方式"复选框

Jak*_*obJ 14 windows-installer wix shortcut

我正在使用WiX工具创建安装程序.

在创建"开始"菜单和"桌面"快捷方式时,我需要安装程序使其成为可选项.

像:[]你想创建一个开始菜单快捷方式吗?

那可能吗?

Nat*_*man 21

是的,这绝对是可能的.一般的想法是使快捷方式组件以属性为条件,然后自定义UI以将复选框连接到该属性.

所有这些都在Wix教程中进行了描述(尽管不是针对您的具体示例),这是一本富有洞察力的读物.但是这里有一些针对您的案例的更具体的代码示例:

添加一个属性

创建一个可以将复选框挂钩的属性.在.wxs文件中,添加一个Property以存储值.

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product ...>
    <Property Id="INSTALLSHORTCUT" />
  </Product>
</Wix>
Run Code Online (Sandbox Code Playgroud)

添加条件

添加Condition到安装快捷方式的组件,因此它取决于新INSTALLSHORTCUT属性的值.

<Component Id="ProgramFilesShortcut" Guid="*">
  <Condition>INSTALLSHORTCUT</Condition>
  <Shortcut Id="ProductShortcut" ... />
</Component>
Run Code Online (Sandbox Code Playgroud)

添加复选框

您需要自定义对话框以向UI添加复选框并将其连接到INSTALLSHORTCUT属性.我不会在这里详细介绍所有细节,但这里有一个很好的教程:重新访问 用户界面

您需要下载wix源代码树以获取您正在使用的UI的.wxs文件.例如,要InstallDirWixUI_InstallDirUI中的对话框中添加复选框,您需要下载WixUI_InstallDir.wxsInstallDirDlg.wxs.将它们添加到您的Wix项目并重命名它们(例如,Custom_InstallDir.wxsCustom_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>
Run Code Online (Sandbox Code Playgroud)

编辑Custom_InstallDir.wxs以使用自定义InstallDirAndOptionalShortcut对话框:

<Wix ...>
  <Fragment>
    <UI Id="Custom_InstallDir">

      ** Search & Replace all "InstallDirDlg" with "InstallDirAndOptionalShortcut" **

    </UI>
  </Fragment>
</Wix>
Run Code Online (Sandbox Code Playgroud)

最后,在主.wxs文件中引用您的自定义UI:

<Wix ...>
  ...
  <UIRef Id="Custom_InstallDir" />
  ...
</Wix>
Run Code Online (Sandbox Code Playgroud)

  • `&lt;Property Id="INSTALLSHORTCUT" Secure="yes"/&gt;` 安全必须设置为 yes 才能通过条件访问此属性。 (2认同)