System.Drawing.Image Image is not working when in run mode.

RAMSANKAR MANTRY 96 Reputation points

I am using ITeamExplorerNavigationItem2 to add a button in the Team Explorer.

When I am using the property public System.Drawing.Image Image to control the button Icon.

public System.Drawing.Image Image => null // Button comes up  without any button icon

public System.Drawing.Image Image => System.Drawing.Image.FromFile("MyImage.png"); // button does not show up in the team explorer

*Note that both are working when I am debugging the Extension i.e. using experimental instance.

What I am suspecting is, during debug it is finding the path of the "MyImage.png" but at run time the Image is not packaged to the VSIX, so it is not finding the .png path and subsequently it is not displaying the icon and button. Can someone help how can I add the image icon ?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,077 questions
0 comments No comments
{count} votes

Accepted answer
  1. RAMSANKAR MANTRY 96 Reputation points

    To fix this issue, I actually added a Resource.resx file to the project and added the Image inside that. Since the resource.resx file is added to VSIX file during compile time it is displayed correctly after installation. The modified code-

     public System.Drawing.Image Image => Resource.MyImage;
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Dylan Zhu-MSFT 6,396 Reputation points


    You could click the image you need, then set "Include in VSIX" to True in properties window.



    Thank you for sharing the sample. You also need to change the codes to get the image, which is installed in the extension installation directory.

            public string GetImageFullPath(string filename)  
                string a = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Resources\\" + filename;  
                return a;  
            public System.Drawing.Image Image => System.Drawing.Image.FromFile(GetImageFullPath("ViewChangeset.png"));  

    Best Regards,