Feb. 1, 2011, 11:59 a.m.
posted by fullstack
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
Add a new Class Library Project to your Add-in Solution (File New Project).
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 editorCompile your Class Library Project and then click the Show All Files button on the Solution Explorer.
Navigate to the obj Debug folder in the Solution Explorer and then double-click on the .dll file.
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
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
- To add assembly:
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 Assembly.
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:
Navigate to HKEY_CURRENT_USER Software Microsoft VisualStudio 7.1 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 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.