microsoft / VSProjectSystem

Documentation for extending Visual Studio with new types of projects.
Other
313 stars 87 forks source link

Solution Explorer icons not working #355

Closed manuelxmarquez closed 2 years ago

manuelxmarquez commented 2 years ago

I have a project with custom solution explorer icons that stopped working in VS2022. I followed the guide but it no longer works.

If I set the icon using propertyValues.Icon = KnownMonikers.CSProjectNode.ToProjectSystemType(); it works, but not for custom icons.

I verified my icons are included in the assembly with ILSpy and even used the following code:

var imageService = ServiceProvider.GetService(typeof(SVsImageService)) as IVsImageService2;
var resource = new BitmapImage(new Uri(@"file:///F:/Test.png"));

var img = Microsoft.Internal.VisualStudio.PlatformUI.WpfPropertyValue.CreateIconObject(resource);
var imgHandle = imageService.AddCustomImage(img);
var moniker = imgHandle.Moniker;

propertyValues.Icon = new ProjectImageMoniker(moniker.Guid, moniker.Id);

But it still shows blank.

What are the new steps to get this working?

manuelxmarquez commented 2 years ago

I managed to fix the issue by adding the ProvideBindingPath attribute to the Package.

[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[Guid(Constants.PackageGuid)]
[ProvideBindingPath] // Fixes icons.
internal sealed class ProjectPackage : AsyncPackage
{
}
soroshsabz commented 1 year ago

@manuelxmarquez I try it, but my problem is not resolved, all of my information is https://stackoverflow.com/q/75481734/1539100 , did you have any other idea?