我该如何使用WiX为关联文件设置图标?

8

我正在使用WiX生成我的应用程序安装文件。在WiX配置中,我将一个与应用程序配合工作的文件类型关联起来。如何在WiX配置中为这个文件类型关联一个图标呢?

4个回答

10

来源: https://www.firegiant.com/wix/tutorial/getting-started/beyond-files/

如果您的应用程序处理自己的文件数据类型,则需要为其注册文件关联。将一个ProgId放在您的组件中。FileId应该引用描述处理此扩展名文件的File元素的Id属性。请注意感叹号:它会返回文件的短路径而不是长路径:

<ProgId Id='AcmeFoobar.xyzfile' Description='Acme Foobar data file'>
  <Extension Id='xyz' ContentType='application/xyz'>
    <Verb Id='open' Sequence='10' Command='Open' Target='[!FileId]' Argument='"%1"' />
  </Extension>
</ProgId>

要将图标分配给此文件类型,您必须在组件内自己指定相应的注册表条目:

<Registry Id='FooIcon1' Root='HKCR' Key='.xyz' Action='write'
  Type='string' Value='AcmeFoobar.xyzfile' />
<Registry Id='FooIcon2' Root='HKCR' Key='AcmeFoobar.xyzfile' Action='write'
  Type='string' Value='Acme Foobar data file' />
<Registry Id='FooIcon3' Root='HKCR' Key='AcmeFoobar.xyzfile\DefaultIcon' Action='write'
  Type='string' Value='[INSTALLDIR]Foobar.exe,1' />

1
而Value='[INSTALLDIR]Foobar.exe,1' />中的Foobar.exe指的是什么?它又在哪里? - Filip

7
这是我的做法。我声明:
<Icon Id="Icon.exe" SourceFile="..\Installer\Graph.ico" />

我在 </Product> 标签之前添加了它,并将其作为以下引用:

<ProgId Id='myApp.exe' Description='Some description' Advertise='yes' Icon='Icon.exe'>
          <Extension Id='xyz' ContentType='application/text'>
            <Verb Id='open' Sequence='10' Command='Open' Argument='"%1"' />
          </Extension>
</ProgId>

对于未公开的 ProgId,请使用 <File/> 而不是 <Icon/> 来引用 ico 文件。 <Verb> 将需要一个 TargetFile,并且需要删除 Sequence。来源:https://dev59.com/1Izda4cB1Zd3GeqPtv2Z#34308271 - Trevor

0

我建议您遵循我的stackoverflow帖子,位于这里,以最简单和最优雅的方式将图标嵌入到资源中,而无需在托管的.NET应用程序中使用c++项目。

接下来,这是通过wix正确设置的方法:

  <Component Id="stackoverflowFileRegistration" Guid="MY_GUID">

    <RegistryKey Root="HKCR" Key=".stackoverflow" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
      <RegistryValue Value="stackoverflow.Document" Type="string" KeyPath="yes" />
      <RegistryValue Name="Content Type" Value="application/stackoverflow" Type="string" />
      <RegistryKey Key="ShellNew" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
        <RegistryValue Name="NullFile" Value="" Type="string" />
        <RegistryValue Name="Data" Value="Default new document Content.. NOTE: you must use a MutiStringValue nodes for multi-line content...." Type="string"/>
      </RegistryKey>
    </RegistryKey>

    <RegistryKey Root="HKCR" Key="stackoverflow.Document" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
      <RegistryValue Value="stackoverflow Document" Type="string" />

      <RegistryKey Key="DefaultIcon" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
        <RegistryValue Value="[INSTALLDIR]bin\stackoverflow.lib.dll, 1" Type="string" />
      </RegistryKey>

      <RegistryKey Key="Shell" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
        <RegistryKey Key="openstackoverflowwebsite" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
          <RegistryValue Value="Open Stackoverflow" Type="string" />
          <RegistryKey Key="command" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
            <RegistryValue Value="&quot;[INSTALLDIR]stackoverflow.exe&quot; /openwebsite &quot;%1&quot;" Type="string" />
          </RegistryKey>
        </RegistryKey>
      </RegistryKey>

    </RegistryKey>
  </Component>

这个示例为步骤1中位于程序集中的特定文件扩展名(.stackoverflow)注册默认图标。它还展示了如何创建与Windows资源管理器相关联的右键命令,并将菜单项添加到Windows资源管理器的“新建”子菜单中。

谢谢

-Blake Niemyjski


-1
请注意,Draco的答案并不足以完成图标/文件关联的全部工作。
以下是代码:
这就是我做的。我声明了:
<Icon Id="Icon.exe" SourceFile="..\Installer\Graph.ico" /> 
<ProgId Id='myApp.exe' Description='Some description' Advertise='yes' Icon='Icon.exe'>
          <Extension Id='xyz' ContentType='application/text'>
            <Verb Id='open' Sequence='10' Command='Open' Argument='"%1"' />
          </Extension>
</ProgId>

仅为由给定的wix项目安装的应用程序创建的对话框注册文件/图标关联。 要在Windows中显示所有对话框、桌面等的图标,还需要在regedit中为特定的文件类型(扩展名)注册您的图标。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接