locked
How to programmatically customize a C# project icon in solution explorer RRS feed

  • Question


  • Within a add-in , can I programmatically customize a standard C# project icon in solution explorer? I don't create a new project type, and don't intend to change icons for all C# projects in solution, but only some of them. 

    I read some threads and they said you can create a C# flavored project type (project subtype) to customize project icon. However, the flavored project type approach seems only available in VSPackage (not add-in). So that means there is no way for add-in to dynamically change the project icon in solution explorer, right?

    Thanks.

     

    Friday, December 3, 2010 5:48 AM

Answers

  • Hi Liang Ye,

    I can confirm Hongye's suspicion that this cannot be done from an add-in. The icons are rendered by the project system's implementation of IVsUIHierarchy.GetProperty. You cannot intercept this outside of building your own project flavor (aka project subtype). This would entail building an addin, as you would essentially be creating a new project system by inheriting the functionality of a base project type (typically VB or C#) and then providing an override of IVsUIHierarchy.GetProperty, to return the desired property values Hongye mentioned in his post.

    Sincerely,


    Ed Dore
    Tuesday, December 7, 2010 5:52 AM

All replies

  • Hi Liang,

    I am not sure if add-in is supported in this senario. Any node in solution explorer will get icon by following steps:

    1. Get VSHPROPID_IconIndex property and if it has value go to 2 else go to 3

    2. Get VSHPROPID_IconImgList property and retrieve the image list and get the icon by icon index.

    3. Get VSHPROPID_IconHandle property and if it has value, VS will get the icon by its handle.

    4. If there is no index and handle returned, VS will use Windows system icon.

    For flavored project type, you can override GetProperty and return not implemented for icon index and return a handle for your own icon.

    I am not sure if SetProperty can work here by setting VSHPROPID_IconIndex and VSHPROPID_IconHandle, because VS may cache the result when it first calls the GetProperty method.


    Looking for TFS Hot Issues? Follow us at Twitter.

    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, December 6, 2010 1:54 PM
  • Hi Liang Ye,

    I can confirm Hongye's suspicion that this cannot be done from an add-in. The icons are rendered by the project system's implementation of IVsUIHierarchy.GetProperty. You cannot intercept this outside of building your own project flavor (aka project subtype). This would entail building an addin, as you would essentially be creating a new project system by inheriting the functionality of a base project type (typically VB or C#) and then providing an override of IVsUIHierarchy.GetProperty, to return the desired property values Hongye mentioned in his post.

    Sincerely,


    Ed Dore
    Tuesday, December 7, 2010 5:52 AM