Hack 91. Change the Icon for Your Add-in

face of an icon for your add-in.By default, when you create a new
Visual Studio add-in, you are given a goofy smiley face icon as the
icon for your add-in. If you plan on sending your add-in out to
anyone, I highly recommend creating your own icon or setting it to a
more appropriate built-in icon. Customizing the icon used with your
add-in is not as easy as it should be. In this hack, you will learn
the steps needed to create this custom icon, and then ensure that it
is installed properly with your add-in.
12.7.1. Creating the Icon
The first step is to create a satellite
assembly and embed an icon in that
assembly. Yes, you actually have to create a new assembly; you
can't just embed the resource in your
add-in's assembly!Add a new Class Library Project to your Add-in Solution (File
double-click on your bitmap to open it), you can create a bitmap. The
size of the bitmap should be 16 by 16, and if you want to use
transparency, use Red: 0, Green: 254, Blue: 0. Figure 12-18 shows the bitmap editor.
Figure 12-18. Bitmap editor

button on the Solution Explorer.Navigate to the obj
and then double-click on the .dll file.Right-click on the root folder and select Add Resource as shown in
Figure 12-19.
Figure 12-19. Add Resource button

shown in Figure 12-20.
Figure 12-20. Add Resource dialog

embedding the bitmap, note the ID of the bitmap since you will be
using that later.
12.7.2. Modify Command Code
The
default code to add a
command created by the Add-in Wizard is
shown here:
Command command = commands.AddNamedCommand(addInInstance,The Boolean value here represents whether the icon you are using is a
"TryCatchMatic", "TryCatchMatic", "Surround W/ Try..Catch",
true, 59, ref contextGUIDS,
(int)vsCommandStatus.vsCommandStatusSupported
+(int)vsCommandStatus.vsCommandStatusEnabled);
Microsoft icon or a custom icon. You will need to change this to
false and then replace the number 59 with the ID of your bitmap.
(This is usually 101, but you can check by double-clicking on your
assembly in Visual Studio and expanding the folder named Bitmap).
Here is the new line of code:
Command command = commands.AddNamedCommand(addInInstance,This command will now try to use the bitmap with the ID 101 in your
"TryCatchMatic", "TryCatchMatic", "Surround W/ Try..Catch",
false, 101, ref contextGUIDS,
(int)vsCommandStatus.vsCommandStatusSupported
+(int)vsCommandStatus.vsCommandStatusEnabled);
new assembly.You could alternatively set the icon to another of the default icons.
You could do this by leaving the Boolean value set to true and then
specifying another number instead of 59. To view a list of all the
available icons, you can use a small utility available from
http://www.visualstudiohacks.com/iconspy.
12.7.3. Add to Installer
Finally,
you need to configure the installer
to include your new assembly and add a couple of new keys to the
registry to tell Visual Studio where your icon is.
Right-click on the setup project and choose View
System.Create a directory called 1033 (or your local version, if you are not
using English) under the Application Folder.Right-click on the 1033 folder and choose Add
your assembly. The final result is shown in Figure 12-21.
Figure 12-21. Setup projectFile System

installed.To add registry keys:Right-click on the setup project and
choose View
Microsoft
AddIns
MacroName.Add a new string value called SatelliteDllName and
enter the name of your .dll file as the value.Add a second string value called SatelliteDllPath
and enter a value of [TARGETDIR]. Figure 12-22 shows the end result.
Figure 12-22. Setup projectregistry settings

your add-in. You may need to run devenv
/setup for your changes to take effect
[Hack #92] .After reinstalling your add-in, you will now see your icon in the
Tools menu, as shown in Figure 12-23.
Figure 12-23. Add-in with new icon

procedures, but it is definitely a must if you
plan on distributing your icon to other users.