WIX 损坏的快捷方式图标

标签 wix

我有一个简单的 wix 设置,安装了一个可执行文件和一些 dll。一切正常,除了桌面快捷方式不是 C:\Program Files 中可执行文件的常规链接,而是隐藏可执行文件位置的一些奇怪的注册表 GUID 类型的链接。最重要的是,该快捷方式的图标来自安装程序文件夹,而不是可执行文件本身的图标。

如何创建一个常规的、简单的 c:\program files\mycompany\myproduct.exe 快捷方式,而不是这个花哨的快捷方式?

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="MyProduct" Language="1033" Version="1.0.0.0" Manufacturer="MyCompany" UpgradeCode="11111111-1111-1111-1111-111111111111">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate EmbedCab="yes" />

        <Feature Id="ProductFeature" Title="MyCompany.Desktop.Setup" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
            <ComponentRef Id='ProgramMenuDir' />
        </Feature>
        <Icon Id="MyProduct.ico" SourceFile="MyProduct.ico" />

        <UI>
            <UIRef Id="WixUI_Minimal" />
            <Publish Dialog="ExitDialog"
                Control="Finish"
                Event="DoAction"
                Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
        </UI>
        <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Open MyProduct now" />
        <Property Id="WIXUI_EXITDIALOGOPTIONALTEXT" Value="Success! MyProduct is now installed." />

        <CustomAction Id="CA_Set_WIXUI_EXITDIALOGOPTIONALTEXT" Property="WIXUI_EXITDIALOGOPTIONALTEXT" Value="Oops! Unfortunately, the installer ran into a problem and MyProduct was not installed."/>
        <InstallUISequence>
            <Custom Action="CA_Set_WIXUI_EXITDIALOGOPTIONALTEXT" After="FindRelatedProducts">Installed</Custom>
        </InstallUISequence>

        <Property Id="WixShellExecTarget" Value="[#MyProductEXE]" />
        <CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="MyProduct">
                </Directory>
            </Directory>

            <Directory Id="ProgramMenuFolder" Name="Programs">
                <Directory Id="ProgramMenuDir" Name="MyProduct">
                    <Component Id="ProgramMenuDir">
                        <RemoveFolder Id='ProgramMenuDir' On='uninstall' />
                        <RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='' KeyPath='yes' />
                    </Component>
                </Directory>
            </Directory>

            <Directory Id="DesktopFolder" Name="Desktop" />
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
            <Component Id="MainExecutable">
                <File Id='MyProductEXE' Source='$(var.MyCompany.Desktop.TargetPath)' KeyPath='yes'>
                    <Shortcut Id="startmenuMyProduct" Directory="ProgramMenuDir" Name="MyProduct" WorkingDirectory='INSTALLDIR' Icon="MyProduct.ico" IconIndex="0"  Advertise="yes" />
                    <Shortcut Id="desktopMyProduct" Directory="DesktopFolder" Name="MyProduct" Description="MyProduct Description" WorkingDirectory='INSTALLDIR' Icon="MyProduct.ico" IconIndex="0" Advertise="yes" />
                </File>
            </Component>
            <Component Id='CommonLibrary'>
                <File Id='CommonDLL' Source='$(var.MyCompany.Desktop.TargetDir)\MyCompany.Common.dll' KeyPath='yes' />
            </Component>
            <Component Id='CSVLibrary'>
                <File Id='CSVDLL' Source='$(var.MyCompany.Desktop.TargetDir)\CsvHelper.dll' KeyPath='yes' />
            </Component>
            <Component Id='InputLibrary'>
                <File Id='WinInpDLL' Source='$(var.MyCompany.Desktop.TargetDir)\WindowsInput.dll' KeyPath='yes' />
            </Component>
        </ComponentGroup>
    </Fragment>
    <Fragment>
        <Component Id="DesktopShortcut" Directory="APPLICATIONFOLDER" Guid="*">
            <RegistryValue Id="RegShortcutDesktop" Root="HKCU" 
                    Key="Software\[Manufacturer]\[ProductName]" Name="DesktopSC" Value="1" 
                    Type="integer" KeyPath="yes" />
            <Shortcut Id="desktopSC" Target="[APPLICATIONFOLDER]MyCompany.Desktop.exe"
                    Directory="DesktopFolder" Name="MyProduct" 
                    Icon="MyProduct.ico" IconIndex="0"
                    WorkingDirectory="APPLICATIONFOLDER" Advertise="no"/>
        </Component>
    </Fragment>
</Wix>

最佳答案

您的产品功能中缺少对 DesktopShortcut 组件的组件引用。您的 ProductFeature 应如下所示:

    <Feature Id="ProductFeature" Title="MyCompany.Desktop.Setup" Level="1">
        <ComponentGroupRef Id="ProductComponents" />
        <ComponentRef Id='ProgramMenuDir' />
        <ComponentRef Id='DesktopShortcut' />
    </Feature>

将您的 DesktopShortcut 组件修改为:

    <!--DesktopShortcut-->
<DirectoryRef Id="DesktopFolder">  
  <Component Id="DesktopShortcut" 
             Guid="GENERATE A GUID FOR THIS COMPONENT">

    <Shortcut Id="desktopSC" 
              Name="MyProduct" 
              Description="MyProduct description" 
              Target="[APPLICATIONFOLDER]MyCompany.Desktop.exe"
              Icon="MyProduct.ico">
    </Shortcut>
    <RemoveFolder Id="RemoveDesktopFolder" 
                  Directory="DesktopFolder" 
                  On="uninstall" />
    <RegistryValue Root="HKCU" 
                   Key="Software\[Manufacturer]\[ProductName]" 
                   Name="installed" 
                   Type="integer" 
                   Value="1" 
                   KeyPath="yes" />
  </Component>
</DirectoryRef>

这将为您的应用程序提供一个普通、老式且简单的桌面快捷方式。 值得一提的几点:

  • 已添加“RemoveFolder”标记。这将确保卸载应用程序时桌面快捷方式也被删除。
  • 确保为您的 DesktopShortcut 组件生成一个不变的 GUID。这保证了安装/卸载过程中文件的一致性和可管理性。
  • 请注意,有一个对桌面文件夹的目录引用,包含在 DesktopShortcut 组件中。这将确保快捷方式放置在正确的位置。 在本例中为桌面。

希望这有帮助!

关于WIX 损坏的快捷方式图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40066499/

相关文章:

installation - 构建运行另一个安装程序的安装程序

c# - Windows 服务未从 App.config 获取值

file - 如何处理 wix 源路径中的空格?

xml - 是否可以使用 XPath 从处理指令 ('define' ) 中提取值?

visual-studio-2012 - 使用wix在程序数据中添加文件

installation - Wix - 创建需要重新启动的模拟安装程序(返回 3010)

command-line - WiX Bootstrap : How do I set burn variables from the command line?

wix - 如何使用 wix bootstrapper 修改 msi 的已安装功能?

wix - MSI 主要升级覆盖规则