For a background intro to Addin technology and Visual Studio automation, take a
look at this article:
Custom Add-Ins Help You Maximize the Productivity
of Visual Studio .NET. This is, in my opinion, one of the most complete
ones (even if it was on Visual Studio 2002).
Some things have changed with new Visual Studio versions, but the basic ideas are
the same.
I tried to learn about many aspects of addin creation experimenting with my addin,
so I hope having a look at code and projects is in some way useful.
First of all addin comes in two flavours: version 1.3 targetting Visual Studio 2003
and version 2.0 targetting Visual Studio 2005.
Addin functionality is the same between versions, and so is internal implementation.
Anyway there are many differences between two IDEs:
- how to add named commands to Visual Studio menus (now implementation is a lot
easier and allows automatically to contemplate localized Visual Studio versions)
- addins are binded and configured in Visual Studio 2003 using registry options
(so Setup Project should take care of it); in Visual Studio 2005 adding an addin
is done using XML configuration file
- same as previous is regarding creating addin option page (registry keys vs xml
files)
- adding a custom icon to menu now can be done creating a managed resource file,
instead of a basic windows resource file (and now Visual Studio 2005 supports high-color
icons)
At last Visual Studio 2005 seems to be a fantastic step ahead from previous version.
These are addin functionalities:
- Check if a banner is already present at top of source code file (active document
in IDE) - supported languages are C# and VB
- If banner is not available, adds a standard copyright message and puts developer
and creation date on banner
- If banner is already there, asks a comment/message to user and appends it, with
current date, to banner
- All messages are customizable using option form: in Visual Studio 2005 use Tools
| Options... | Sharp Add-Ins; in Visual Studio 2003 use Tools | Options... | Add
History Banner AddIn
- Banner comments length can be customized with max length. If comment length exceeds
max, string will be splitted at last word
- Comment adding in banner is considered atomic operation - so it can be undone
using a single Undo action
- Addin operation is available through Edit Menu and through keyboard shortcut -
ALT+L, ALT+H (Keep in mind changing keyboard shortcut on Visual Studio 2003 requires
a writable "Keyboard mapping scheme" - usually simply copy default one or you'll
get a message during addin loading)
- Editing point is not changed when adding comments, so you can add history and
continue working, without suffering page moves
- Either projects contain custom icons for menu item, custom about box and fully
working setup projects
Last note should be about adding and using customized resources in addins.
You will find in each project custom external DLL with source and icons to understand
the process.
In Visual Studio 2003 you must create icons - keep in mind particular color in palette
indicating transparency - and embed them in a simple DLL.
I accomplished this task using this tool:
Resource Hacker by Angus Johnson.
Resource ID is then referred when adding new menu item to Visual Studio.
In Visual Studio 2005 things are easier, you simply need to create a managed resources
DLL embedding custom icon. Batch script is included showing this technique.
One of the biggest source of tricks and code about Visual Studio Addins is:
Craig Skibo's WebLog.
I updated Add History Banner 2 to version 2.1, reimplementing configuration settings
saving in XML configuration file instead of registry. Saving and creating registry
keys leads to some phantom items in Add-in list in Visual Studio 2005. This is due
to the fact registry is not anymore used for Add-in configuration, but if some
keys are there, IDE can look at them and try to use them. Persisting configuration
in XML, using .NET 2.0 impressive new configuration facility, brings more polished
code and ability to get user defined preferences out of the box.