HOWTO: Provide command bitmaps from embedded resources of a Visual Studio package.

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2010
Date: August 2014   Microsoft Visual Studio 2012
      Microsoft Visual Studio 2013

When you create a package with a command using the package wizard, by default the command bitmaps are provided in the .vsct file from bitmap files on disk:

    <Bitmap guid="guidImages" href="Resources\Images_32bit.bmp" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows"/>

This article explains how to provide the command bitmaps from embedded resources from the package assembly, rather than from files. This could be useful in a couple of scenarios:

  • You don't want to hardcode the names of files in the .vsct file.
  • For some reason, your package needs to use the command bitmaps at run-time so they are embedded in the assembly.

Note: although the command bitmaps are supplied from embedded resources, they are supplied at compile-time, not at run-time, since the .vsct command table file is compiled into a .cto file that is embedded in the compiled assembly.

More Information

To create a package whose commands bitmaps are provided from embedded resources follow these steps:

  • Create a package with the package wizard, with a command in the "Tools" menu.
  • Open the "Resources.resx" file.
  • In the toolbar of the editor, click the first button "Strings" and change it to "Images".
  • Click the "Add Resource" > "Add Existing File..." and select a 16x16 image file.
  • In the editor, rename it from its original name to some numeric value, such as 101.
  • In the .vsct file, use this code in the corresponding sections. Notice the use of the resId attribute instead of the href attribute:
<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
   <Bitmap guid="guidImages" resID="bmpMyBitmap" usedList="bmpPic1"/>
<GuidSymbol name="guidImages" value="{<your_images_guid>}" >
   <IDSymbol name="bmpMyBitmap" value="101" />
   <IDSymbol name="bmpPic1" value="1" />

Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)