【问题标题】:Wix installer: create shortcut to open a folderWix 安装程序:创建打开文件夹的快捷方式
【发布时间】:2014-05-29 16:50:49
【问题描述】:

我对 Wix 和一般的安装问题不熟悉,因此希望在以下方面提供任何帮助。 我想做一个相当标准的应用程序安装(TestApp.exe),但我希望安装文件夹有一个包含教程文档和几个示例文件的子文件夹。我希望开始程序 (ProgramMenuFolder) 中的应用程序子文件夹有 3 个快捷方式:1) 应用程序 exe 本身,2) 到 tutorial.docx 文件,以及 3) 到包含 tutorial.docx + 示例文件的子文件夹。最后一个快捷方式的想法是单击它应该在资源管理器中打开文件夹,以便用户可以访问示例文件以加载到应用程序中。 我的问题是我不知道如何编写文件夹的快捷方式。这是我的代码,它适用于一般安装和前两个快捷方式。它包括我对第三条捷径的可悲尝试。它编译正常,但无法将快捷方式写入文件夹 我将非常感谢有关如何实现第三个快捷方式的建议。

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

    <Product Id="*" Name="TestApp" Language="1033" Version="2.0.0.0" Manufacturer="W J Heitler" UpgradeCode="be9cef4c-d9e8-488e-b69d-00b7d1f1250b">
        <Package Id="*" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

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

    <Feature Id='Complete' Title ='TestApp Complete' Level='1'>
      <ComponentGroupRef Id='ProductComponents' />
      <ComponentGroupRef Id='Shortcuts' />
      <ComponentGroupRef Id='TutorialStuff' />
    </Feature>

    <Icon Id="TestApp.exe" SourceFile="..\Release\TestApp.exe" />

  </Product>

<!--Directories-->
  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLDIR" Name="TestApp" >
          <Directory Id="INSTALLDIRTUTORIAL" Name="Tutorial" />
        </Directory>
      </Directory>
      <Directory Id="ProgramMenuFolder" Name="Programs">
        <Directory Id="ProgramMenuDir" Name="TestApp"/>
      </Directory>
    </Directory>  
  </Fragment>

<!--Bits to install-->
  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLDIR">
      <Component Id="MainExecutable" Guid="{E758641D-5794-412B-97FD-A7879C276947}">
        <File Id="TestAppEXE" Source="$(var.TestApp.TargetPath)" KeyPath="yes" >
          <Shortcut Id="TestApp" Directory="ProgramMenuDir" Name="TestApp" WorkingDirectory='INSTALLDIR' Icon="TestApp.exe" IconIndex="0" Advertise="yes" />
        </File>
      </Component>
    </ComponentGroup>

    <ComponentGroup Id='Shortcuts' Directory='ProgramMenuDir'>
      <Component Id="ProgramMenuShortcut"  Guid="{EBFD85FD-27B4-48CE-9AE3-E7B186A7F797}">
        <RemoveFolder Id='ProgramMenuDir' On='uninstall' />
        <RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='' KeyPath='yes' />
      </Component>
    </ComponentGroup>

    <ComponentGroup Id ='TutorialStuff' Directory='INSTALLDIRTUTORIAL'>
      <Component Id ='Tutorial' Guid='{02DDC1B6-DFBB-488F-BDEF-8D32D95DEBC4}' >
        <File Id='TutorialDoc' Source='samples\tutorial.docx' KeyPath='yes' >
          <Shortcut Id='TutorialSC' Directory='ProgramMenuDir' Name='Tutorial' WorkingDirectory='INSTALLDIRTUTORIAL' Advertise="yes" />
        </File>
      </Component>

      <!-- THIS DOES NOT WORK-->
      <Component Id ='SampleDir' Guid='{E9EAE95A-8234-406D-950D-397956287709}' >
        <Shortcut Id='SampleDirSC' Directory='ProgramMenuDir' Name='Samples' Target ='INSTALLDIRTUTORIAL' />
        <RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='' KeyPath='yes' />
      </Component>
      <!--END OF FAILED CODE-->
  </ComponentGroup>

  </Fragment>

</Wix>

【问题讨论】:

    标签: wix installation shortcut


    【解决方案1】:

    我认为您错过的是用方括号将Target-attribute 中的目录标识符括起来,以便Windows Installer 可以正确解析目录。另请注意,在这种情况下,快捷方式本身必须是非广告的。我还将Directory-attribute 包含到周围的组件中,就像您对其他组件所做的那样。所以以下应该工作:

      <Component Id ='SampleDir' Guid='{Add_your_guid_here}' Directory='INSTALLDIRTUTORIAL' >
        <Shortcut Id='SampleDirSC' Directory='INSTALLDIRTUTORIAL' Name='Samples' Target ='[INSTALLDIRTUTORIAL]' Advertise='no' />
        <RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='' KeyPath='yes' />
      </Component>
    

    另请参阅有关 Shortcut-元素的 Target-属性的 WiX 文档:

    此属性的值是非广告快捷方式的目标。此属性对广告的快捷方式无效。如果您指定此值,它的值应该是用方括号 ([ ]) 括起来的属性标识符,即展开到快捷方式指向的文件或文件夹中。

    【讨论】:

    • @Paddy:我不知道如何评论编辑。在这种情况下,删除 GUID 不再适合具体问题的解决方案。随便。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多