是否可以在WIX​​的多个位置使用相同的组件(快捷方式)?

时间:2015-07-17 05:00:12

标签: wix shortcut

免责声明:我被迫通过项目要求从我最喜欢的尝试和真实的VS安装项目跳到WIX,据我所知,VS安装项目无法实现(如here所述) 。因此,对于WIX来说,我真的非常新,所以这可能是一个很好的" duh"问题

尝试慢慢来,我正在学习如何在桌面和程序文件菜单上创建主要可执行文件的快捷方式。我已经找到了如何创建一个组件,并将其粘贴在将包含主文件的ComponentGroup中(可能是一个错误的移动),所以这就是我到目前为止所做的:

super

我想要一个快捷方式转到桌面,另一个转到程序菜单快捷方式。为此,我定义了以下文件夹结构:

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
        <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
        <Component Id="CMP_FooSetup">
            <File Id="FILE_Foo.exe" Source="$(var.Foo.TargetPath)" KeyPath="yes"/>
        </Component>
        <Component Id="ApplicationShortcut">
            <Shortcut
                Id="FooShortcut"
                Name="Foo"
                Description="Foos your Bar."
                Target="[#FILE_Foo.exe]"
                WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
            <RegistryValue
                Root="HKCU"
                Key="Software\FooCompany\Foo"
                Name="installed" Type="integer" Value="1"
                KeyPath="yes"/>
            <RemoveFile Id="RemoveFooShortcut" Name="Foo.lnk" On="uninstall"/>
        </Component>
    </ComponentGroup>

我骨子里的所有东西和作为程序员的经验(虽然它可能有限)都尖叫着&#34;嘿,我应该能够使用目录结构中的快捷方式组件的ID来指示安装程序创建这些快捷方式!&#34;,但我不知道该怎么做。似乎它应该是相当简陋的,但我的搜索没有任何结果。

这可能吗?如果是这样;怎么样?如果不;我应该怎么做才能使这项工作?

请善待......

1 个答案:

答案 0 :(得分:1)

无法在多个位置(目录)中使用组件。另一种方法是创建多个组件,将Directory属性从ComponentGroup移动到Component标记。

<ComponentGroup Id="ProductComponents">
    <Component Id="CMP_FooSetup" Directory="INSTALLFOLDER">
        <File Id="FILE_Foo.exe" Source="$(var.Foo.TargetPath)" KeyPath="yes"/>
    </Component>
    <Component Id="ApplicationShortcut" Directory="INSTALLFOLDER">
        <Shortcut
            Id="FooShortcut"
            Name="Foo"
            Description="Foos your Bar."
            Target="[#FILE_Foo.exe]"
            WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
        <RegistryValue
            Root="HKCU"
            Key="Software\FooCompany\Foo"
            Name="installed" Type="integer" Value="1"
            KeyPath="yes"/>
        <RemoveFile Id="RemoveFooShortcut" Name="Foo.lnk" On="uninstall"/>
    </Component>
    <!-- Here I added the Directory attrib and changed the Id. -->
    <Component Id="DesktopShortcut" Directory="DesktopFolder">
        <Shortcut
            <!-- New Id -->
            Id="FooShortcutDesktop"
            Name="Foo"
            Description="Foos your Bar."
            Target="[#FILE_Foo.exe]"
            WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
        <RegistryValue
            Root="HKCU"
            Key="Software\FooCompany\Foo"
            <!-- New Name -->
            Name="installed_desktop" Type="integer" Value="1"
            KeyPath="yes"/>
        <!-- New Id -->
        <RemoveFile Id="RemoveFooShortcutDesktop" Name="Foo.lnk" On="uninstall"/>
    </Component>
</ComponentGroup>

正如您所问,可以更改wxs以将组件包含在Directory标记内,如下所示:

...
<Directory Id="DesktopFolder">
    <Component>
        <Shortcut ... />
    </Component>
</Directory>
...