如何在Visual Studio中将自定义图标添加到解决方案资源管理器 [英] How to add custom icons to solution explorer in Visual Studio

查看:188
本文介绍了如何在Visual Studio中将自定义图标添加到解决方案资源管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将自定义图标添加到Visual Studio中的解决方案资源管理器中,就像 FileIcons扩展可以.

I am trying to add custom icons to the solution explorer in Visual Studio, the same way the FileIcons extension does.

我想我已经为Visual Studio做了一切正确的工作,以将新图标与以.d.di扩展名结尾的文件相关联,但是Visual Studio仍未在解决方案资源管理器中显示任何图标.

I think I've done everything right for Visual Studio to associate the new icon with files ending with the .d and .di extensions, but Visual Studio still doesn't show any icon in the solution explorer.

这是用ManifestFromResources.exe生成的清单:

<?xml version="1.0" encoding="utf-8"?>
<!-- This file was generated by the ManifestFromResources tool.-->
<!-- Version: 14.0.50929.2 -->
<ImageManifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/VisualStudio/ImageManifestSchema/2014">
  <Symbols>
    <String Name="Resources" Value="/VisualDLS;Component/Icons" />
    <Guid Name="AssetsGuid" Value="{872b4702-eabf-444b-b6b3-96dc64531f74}" />
    <ID Name="d" Value="0" />
  </Symbols>
  <Images>
    <Image Guid="$(AssetsGuid)" ID="$(d)">
      <Source Uri="$(Resources)/d.png">
        <Size Value="32" />
      </Source>
    </Image>
  </Images>
  <ImageLists />
</ImageManifest>

这是pkgdef文件:

Here is the pkgdef file:

[$RootKey$\ShellFileAssociations\.d]
"DefaultIconMoniker"="872b4702-eabf-444b-b6b3-96dc64531f74:0"
[$RootKey$\ShellFileAssociations\.di]
"DefaultIconMoniker"="872b4702-eabf-444b-b6b3-96dc64531f74:0"

在扩展程序的vsixmanifest中,将pkgdef文件定义为具有以下属性的资产:

In my extension's vsixmanifest, the pkgdef file is defined as an asset with the following properties:

  • 类型:Microsoft.VisualStudio.VsPackage
  • 来源:File on filesystem
  • 路径:icons.pkgdef(显然,这是我命名pkgdef文件的方式)
  • Type: Microsoft.VisualStudio.VsPackage
  • Source: File on filesystem
  • Path: icons.pkgdef (which is, obviously, how I named my pkgdef file)

关于文件属性,图标图像文件被设置为资源,而图像清单和pkgdef文件都被设置为要包含在VSIX中的内容.

Regarding file properties, the icon image file is set as a resource, while the image manifest and the pkgdef file are both set as content to be included in the VSIX.

如果我尝试在图像清单中使用KnownMoniker,则Visual Studio会正确拾取它并正确显示图标.如果我事先安装它,甚至可以从FileIcons扩展中引用图标别名.但是,一旦我尝试使用自己的清单和图标,就什么也没有显示. 我可能在这里做错了,但我似乎无法确切看到.

If I try to use a KnownMoniker instead in my image manifest, Visual Studio picks it up correctly and displays the icon properly; and I can even reference icon monikers from the FileIcons extension if I install it beforehand. But as soon as I try to use my own manifest and icon, nothing shows up. I'm probably doing something wrong here, but I can't seem to see what exactly.

推荐答案

对于将来可能会偶然发现相同问题的任何人,我都知道我的问题所在.在我的初始测试中,我一定做错了什么,导致Visual Studio在资源管理器中的.d文件旁边不显示任何图标. 之后,即使在更正了我做错的所有事情之后,由于某个地方的图标缓存,它也可能继续这样做.将文件重命名为另一个扩展名,然后将其重命名为原始名称后,新图标开始显示.

For anyone who could randomly stumble upon the same problem in the future, I found what my issue was. During my initial tests, I must have done something wrong, leading Visual Studio to show no icon in the explorer next to the .d files. Afterwards, it probably continued doing so because of an icon cache somewhere, even after correcting whatever I had done wrong. After renaming the file with another extension, and then renaming it back to its original name, the new icon started showing up.

这篇关于如何在Visual Studio中将自定义图标添加到解决方案资源管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆