WiX 3.8;桌面快捷方式取决于所选功能

时间:2014-07-07 15:37:29

标签: wix desktop-shortcut

我正在努力创建一个桌面快捷方式,具体取决于WiX-Installer中所选的功能。如果我运行安装程序,则不会显示任何快捷方式。如果只选择一个特征或两者都无关紧要。那里有什么想法吗?

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="XXX" Name="MyProduct" Language="1031" Codepage="1252" Version="4.4.0" Manufacturer="MyCompany" UpgradeCode="XXX">
    <Package Description="MyProductDescription" Comments="someText" InstallerVersion="400" Compressed="yes" InstallScope="perMachine" Languages="1031"/>
    <Media Id="1" Cabinet="application.cab" EmbedCab="yes" CompressionLevel="high"/>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder" Name="PFiles">
            <Directory Name="LfF" Id="INSTALLDIR">
                <Directory Id="BIN" Name="bin"/>
                    <Component Id="App1.exe" Directory="BIN" Guid="XXX">
                        <File Id="App1.exe" KeyPath="yes" Source="$(var.src)\App1.exe" />
                    </Component>
                    <wix:Component Id="DesktopShortcutApp1" Directory="DesktopFolder" Guid="" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
                        <wix:Shortcut Id="desktopShortcutApp1" Directory="DesktopFolder" Name="App1.exe" Target="[App1.exe]" WorkingDirectory="BIN" Icon="DesktopIconApp1.exe" IconIndex="0" />
                        <wix:RegistryValue Root="HKCU" Key="Software\[Manufacturer]\App1_Desktop_Shortcut" Name="installed" Type="integer" Value="1" />
                    </wix:Component>
                    <Component Id="App2.exe" Directory="BIN" Guid="XXX">
                        <File Id="App2.exe" KeyPath="yes" Source="$(var.src)\App2.exe" />
                    </Component>
                    <wix:Component Id="DesktopShortcutApp2" Directory="DesktopFolder" Guid="" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
                        <wix:Shortcut Id="desktopShortcutApp2" Directory="DesktopFolder" Name="App2.exe" Target="[App2.exe]" WorkingDirectory="BIN" Icon="DesktopIconApp2.exe" IconIndex="0" />
                        <wix:RegistryValue Root="HKCU" Key="Software\[Manufacturer]\App2_Desktop_Shortcut" Name="installed" Type="integer" Value="1" />
                    </wix:Component>
                </Directory>
            </Directory>
        </Directory>
        <Directory Id="DesktopFolder"/>
        <Directory Id="ProgramMenuFolder">
            <Directory Id="ProgramMenuDir" Name="MyProductName">
                <Component Id="StartMenuShortcuts" Guid="XXX">
                    <RemoveFolder Id="ProgramMenuDir" On="uninstall"/>
                    <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value=""/>
                </Component>
            </Directory>
        </Directory>
    </Directory>
    <Feature Id="App1" Level="1" Title="App1" TypicalDefault="advertise">
        <ComponentRef Id="App1.exe" />
        <ComponentRef Id="DesktopShortcutApp1" />
    </Feature>
    <Feature Id="App2" Level="1" Title="App2" TypicalDefault="advertise">
        <ComponentRef Id="App2.exe" />
        <ComponentRef Id="DesktopShortcutApp2"/>
    </Feature>
    <UI>
    </UI>
    <WixVariable Id="WixUIBannerBmp" Value="..\src\bannerapp.bmp"/>
    <WixVariable Id="WixUIDialogBmp" Value="..\src\dialogapp.bmp"/>
    <UIRef Id="WixUI_FeatureTree_NoLicense"/>
    <Icon Id="DesktopIconApp1.exe" SourceFile="$(var.src)\App1.exe"/>
    <Icon Id="DesktopIconApp2.exe" SourceFile=".$(var.src)\App2.exe"/>            
</Product>

该脚本是原始脚本的缩短版本。 Directory Id="BIN"的内容是通过heat.exe生成的,并使用xslt进行修改。

1 个答案:

答案 0 :(得分:0)

经过大量尝试和错误后,我找到了解决方案。

  1. 将快捷方式元素设为包含文件元素的组件的子元素
  2. 将icon元素设为快捷元素的子元素
  3. 在每个功能中设置Level="32767"TypicalDefault="install"(表示:不安装该功能)
  4. 在设置过程中,选择您要安装的功能,仅针对此/这些将创建desktopshortcut。

    以下是代码:

    <?xml version="1.0" encoding="utf-8"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
        <Product Id="XXX" Name="MyProduct" Language="1031" Codepage="1252" Version="4.4.0" Manufacturer="MyCompany" UpgradeCode="XXX">
            <Package Description="MyProductDescription" Comments="someText" InstallerVersion="400" Compressed="yes" InstallScope="perMachine" Languages="1031"/>
            <Media Id="1" Cabinet="application.cab" EmbedCab="yes" CompressionLevel="high"/>
            <Directory Id="TARGETDIR" Name="SourceDir">
                <Directory Id="ProgramFilesFolder" Name="PFiles">
                    <Directory Name="LfF" Id="INSTALLDIR">
                        <Directory Id="BIN" Name="bin"/>
                            <Component Id="App1.exe" Directory="BIN" Guid="XXX">
                                <File Id="App1.exe" KeyPath="yes" Source="$(var.src)\App1.exe" />
                                <Shortcut Id="desktopShortcutApp1" Directory="DesktopFolder" Name="App1.exe" WorkingDirectory="BIN" Advertise="yes">
                                    <Icon Id="DesktopApp1.ico" SourceFile="$(var.src)/App1.ico" />
                                </Shortcut>
                            </Component>
                            <Component Id="App2.exe" Directory="BIN" Guid="XXX">
                                <File Id="App2.exe" KeyPath="yes" Source="$(var.src)\App2.exe" />
                                <Shortcut Id="desktopShortcutApp2" Directory="DesktopFolder" Name="App2.exe" WorkingDirectory="BIN" Advertise="yes">
                                    <Icon Id="DesktopApp2.ico" SourceFile="$(var.src)/App2.ico" />
                                </Shortcut>
                            </Component>
                        </Directory>
                    </Directory>
                </Directory>
                <Directory Id="DesktopFolder"/>
                <Directory Id="ProgramMenuFolder">
                    <Directory Id="ProgramMenuDir" Name="MyProductName">
                        <Component Id="StartMenuShortcuts" Guid="XXX">
                            <RemoveFolder Id="ProgramMenuDir" On="uninstall"/>
                            <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value=""/>
                        </Component>
                    </Directory>
                </Directory>
            </Directory>
            <Feature Id="App1" Level="32767" Title="App1" TypicalDefault="install">
                <ComponentRef Id="App1.exe" />
            </Feature>
            <Feature Id="App2" Level="32767" Title="App2" TypicalDefault="install">
                <ComponentRef Id="App2.exe" />
            </Feature>
            <UI>
            </UI>
            <WixVariable Id="WixUIBannerBmp" Value="$(var.src)/bannerapp.bmp"/>
            <WixVariable Id="WixUIDialogBmp" Value="$(var.src)/dialogapp.bmp"/>
            <UIRef Id="WixUI_FeatureTree_NoLicense"/>    
        </Product>
    </Wix>