FileIcons icon indicating copy to clipboard operation
FileIcons copied to clipboard

New icon (for custom file type) is not displayed (no icon, just blank)

Open ZarehD opened this issue 4 years ago • 16 comments

Installed product versions

  • Visual Studio: 16.10.4
  • This extension: 2.8

Description

Let me just start by saying that this is an unconventional issue request, so I really hope it's alright with you.

I'm attempting to create an extension that assigns a custom icon (myconfig.png) to a custom file type (*.mycfg) in Solution Explorer. The issue is that when a known-moniker icon is specified, the icon is displayed in S/E, but when a custom icon is specified, it is not displayed at all (it's blank).

After scouring the web and finding no reliable/definitive solution, I tried to add the custom file-type icon to this project to see if it would display the custom icon. The results were the same. So I'm hoping that solving the issue in this project will help me (and others) figure out the problem in general. Like I said, unconventional :-)

Steps to recreate

  1. Add my custom 32x32 png file (myconfig.png, a renamed copy of clojure.png) to the Icons folder;
  2. Here are the changes to Monikers.imagemanifest:
    <Symbols>
        <ID Name="myconfig" Value="81" />
    </Symbols>
    <Images>
        <Image Guid="$(MonikersGuid)" ID="$(myconfig)">
            <Source Uri="$(Resources)/myconfig.png">
                <Size Value="32" />
            </Source>
        </Image>
    </Images>
  1. Add following to icons.pkgdef:
[$RootKey$\ShellFileAssociations\.mycfg]
"DefaultIconMoniker"="KnownMonikers.ConfigureComputer" -- icon is displayed
"DefaultIconMoniker"="cb4a8fc6-efe7-424a-b611-23adf22b568e:81"  -- no icon displayed (it's blank)
  1. Run F5/debug in experimental instance of VS2019, load a solution that contains a solution item with file type *.mycfg. An icon is NOT displayed if the custom setting is used, but DOES display if a known-moniker is specified.
  2. Same issue if the extension is built and installed in the IDE (the normal, non-debug/experimental instance).

Current behavior

No icon is displayed for the custom file type in Solution Explorer -- it's blank!

Expected behavior

The configured icon should be displayed next to the custom file type in Solution Explorer.

ZarehD avatar Jul 30 '21 23:07 ZarehD

@ZarehD Have you found a solution to this problem? All my extension icons stopped working in about the last year and trying to figure out why. It seems there are no answers to this problem. Otherwise, I will have to post on VSProjectSystem

manuelxmarquez avatar May 14 '22 17:05 manuelxmarquez

I'm sorry, but no I have not.

It seemed like it would be a pretty simple solution to just copy/paste/rename an existing entry to add another icon to this package to see if would work, but no-o-o-o! ;-)

ZarehD avatar May 16 '22 06:05 ZarehD

That's too bad. I posted here but that repo doesn't seem too active with answers so I'm not sure if I'll get an answer. I have noticed other projects having issues with the icons as well.

Hopefully someone figures it out but I have wasted many hours on this already so I just grabbed the MS ones with propertyValues.Icon = KnownMonikers.PYProjectNode.ToProjectSystemType();

namespace Microsoft.VisualStudio.Imaging Assembly Microsoft.VisualStudio.ImageCatalog

manuelxmarquez avatar May 16 '22 15:05 manuelxmarquez

Yeah, I spent way too many hours on this too; I had to move on.

ZarehD avatar May 16 '22 23:05 ZarehD

@ZarehD I managed to fix the issue and posted the solution here

Hopefully it solves your issue too!

manuelxmarquez avatar May 27 '22 21:05 manuelxmarquez

ITNOA

@madskristensen Did you have any idea to resolve this issue? I have same issue, as you can see in https://stackoverflow.com/q/75481734/1539100

soroshsabz avatar Feb 17 '23 16:02 soroshsabz

@ZarehD @manuelxmarquez

please vote up related to https://developercommunity.visualstudio.com/t/New-icon-for-custom-file-type-is-not-d/10283644 and https://stackoverflow.com/q/75481734/1539100

soroshsabz avatar Feb 17 '23 16:02 soroshsabz

Thanks @manuelxmarquez. Unfortunately, your solution applies to a custom VsPackage implementation. There's nowhere to apply the ProvideBindingPath attribute in what I've described.

ZarehD avatar Feb 23 '23 01:02 ZarehD

@soroshsabz, I upvoted your related VS Community ticket and added a comment.

ZarehD avatar Feb 23 '23 01:02 ZarehD

The attribute just ends up writing to the generated .pkgdef file. You can write it in a .pkgdef file yourself.

madskristensen avatar Feb 23 '23 16:02 madskristensen

@madskristensen, forgive me for not being as up-to-speed on this, but do you mean something like this?

[ProvideBindingPath]
[$RootKey$\ShellFileAssociations\.mycfg]
"DefaultIconMoniker"="cb4a8fc6-efe7-424a-b611-23adf22b568e:81"

I tried that in my own extension (where I'm also having this issue). It didn't break anything, but it didn't help either, unfortunately.

ZarehD avatar Feb 24 '23 04:02 ZarehD

Like this:

[$RootKey$\BindingPaths\{40F7B769-CB63-4CCD-A80C-1FE6A0A07666}]
"$PackageFolder$"=""

Where the GUID is the package guid

madskristensen avatar Feb 24 '23 19:02 madskristensen

Hi @madskristensen.

There's no GUID for icons.pkgdef, so it's unclear which Package GUID you mean. I tried the following values (with no success):

  • GUID from another IVsPackage that happens to exist in the same .vsixmanifest;
  • The VSIX ID (value of ID property in .vsixmanifest)

I left "$PackageFolder$"="", as you've shown. Should I have assigned a value? If so, what? The full path to the location of the .vsixmanifest on my system? a "." or ".\"? Something like %CurrentFolder% or some such?

Finally, it's curious that this extension (FileIcons) is able to add its own custom icons without needing to use this code/attribute.

Thanks for your patience.

ZarehD avatar Feb 24 '23 23:02 ZarehD

@madskristensen Just to follow up, I also tried the following, but too made no difference.

AssemblyInfo.cs

[assembly: Guid("8E436A12-A868-4DBF-8EE0-BFD41F363153")]

Icons.pkgdef

$RootKey$\BindingPaths\{8E436A12-A868-4DBF-8EE0-BFD41F363153}]
"$PackageFolder$"=""

ZarehD avatar Mar 03 '23 23:03 ZarehD

So, I was finally able to resolve the issue in my own VSIX related to using a custom image for my custom file type. Yay!

Although unrelated to this issue (#280), the issue for me was that the reference to the assembly containing the image resources (specified in the generated Monikers.imagemanifest file) was referencing a signed assembly but did not specify the pub-key and version number attributes. Also, the assembly culture (en-US in my case) didn't match the neutral culture presumed in the assembly reference.

Here's the assembly reference that's generated in the .imagemanifest file: <String Name=“Resources” Value=“/MyVSIX;Component/…” />

Here's what it has to be for it to work with my signed assembly: <String Name=“Resources” Value=“/MyVSIX;v1.0.0.0;2f597162cc0d457a;Component/…” />

JFC, Monikers.imagemanifest is being generated using the Image Manifest Tools extension (also by Mads. Thanks, Mads).

So, if the referenced assembly is not signed, the generated .imagemanifest will work fine (provided the assembly is using neutral culture). However, for a signed assembly, the generated reference must be modified to include the pub-key token, the EXACT assembly version (assembly, not file version), and the assembly culture must be neutral (or specified in the assembly reference somehow -- I could not find the correct format, or maybe culture cannot be specified there?).

Still unresolved, tho: adding a new/custom image to this extension for a custom file type by just adding a new image file as a resource (set correct properties, matching existing image files) and re-gen the .imagemanifest file (plus adding the appropriate entry in icons.pkgdef).

ZarehD avatar Mar 18 '23 01:03 ZarehD

So, if the referenced assembly is not signed, the generated .imagemanifest will work fine (provided the assembly is using neutral culture).

This is not true it doesn't work with unsigned assemblies (at least not anymore).

The whole custom image functionality has been broken by a Visual Studio update, even though they made exceptions for their own extensions.

Please see and upvote here: https://developercommunity.visualstudio.com/t/VSSDKCPSExtensibility:-Image-Loading-i/10525678

softworkz avatar Nov 28 '23 16:11 softworkz