问题
I am trying to add custom icons to the solution explorer in Visual Studio, the same way the FileIcons extension does.
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.
Here is the manifest generated with 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>
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"
In my extension's vsixmanifest, the pkgdef file is defined as an asset with the following properties:
- Type:
Microsoft.VisualStudio.VsPackage
- Source:
File on filesystem
- Path:
icons.pkgdef
(which is, obviously, how I named my pkgdef file)
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.
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.
回答1:
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.
来源:https://stackoverflow.com/questions/50896478/how-to-add-custom-icons-to-solution-explorer-in-visual-studio