Change the Icon for Your Add-in





Change the Icon for Your Add-in

Learn how to replace that not-so-lovely smiley 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.

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!

  1. Add a new Class Library Project to your Add-in Solution (File New Project).

  2. Add a new bitmap to your project. Using the bitmap editor (just 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 shows the bitmap editor.

    Bitmap editor
    Compile your Class Library Project and then click the Show All Files button on the Solution Explorer.

  3. Navigate to the obj Debug folder in the Solution Explorer and then double-click on the .dll file.

  4. Right-click on the root folder and select Add Resource as shown in Figure.

    Add Resource button
    From the Add Resource dialog, select Icon and then click on Import as shown in Figure.

    Add Resource dialog
    Navigate to your bitmap file and click OK.

Your icon will now be embedded in the satellite assembly. After embedding the bitmap, note the ID of the bitmap since you will be using that later.

Modify Command Code

The default code to add a command created by the Add-in Wizard is shown here:

Command command = commands.AddNamedCommand(addInInstance, 

"TryCatchMatic", "TryCatchMatic", "Surround W/ Try..Catch", 

true, 59, ref contextGUIDS, 

(int)vsCommandStatus.vsCommandStatusSupported

+(int)vsCommandStatus.vsCommandStatusEnabled);

The Boolean value here represents whether the icon you are using is a 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, 

"TryCatchMatic", "TryCatchMatic", "Surround W/ Try..Catch", 

false, 101, ref contextGUIDS, 

(int)vsCommandStatus.vsCommandStatusSupported

+(int)vsCommandStatus.vsCommandStatusEnabled);

This command will now try to use the bitmap with the ID 101 in your 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.

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.


To add assembly:

  1. Right-click on the setup project and choose View File System.

  2. Create a directory called 1033 (or your local version, if you are not using English) under the Application Folder.

  3. Right-click on the 1033 folder and choose Add Assembly.

  4. This will display the Add Assembly dialog from which you can select your assembly. The final result is shown in Figure.

Figure. Setup project—File System


Your satellite assembly will now be installed when your add-in is installed.

To add registry keys:

  1. Right-click on the setup project and choose View Registry.

  2. Navigate to HKEY_CURRENT_USER Software Microsoft VisualStudio 7.1 AddIns MacroName.

  3. Add a new string value called SatelliteDllName and enter the name of your .dll file as the value.

  4. Add a second string value called SatelliteDllPath and enter a value of [TARGETDIR]. Figure shows the end result.

Figure. Setup project—registry settings


Next, you will need to rebuild your setup project and then reinstall 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.

Add-in with new icon


Adding a custom icon for your add-in is not the easiest of procedures, but it is definitely a must if you plan on distributing your icon to other users.


     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows