Writing a Visual Studio.Net 2003 Add-in

One of my favourite functionality in Visual Studio is to close all document except the one I am working on. Before, I used VS 2003 with ReSharper and I had it, but now withuot ReSharper, I don’t have that luxury any more. So I decided to write one for me.

Use Visual Studio Add-in wizard and it creates the basic skeleton codes. One hurdle was to find the name of the pop-up menu that comes when you click on document Tab. I used Command Browse Add-in and it displayed all menu and window names I can use. Also, there are many good add-in examples.

Available resources

There are some good articles on VS 2003 Automation
all the list of add-ins: http://www.codeproject.com/macro/#Visual+Studio+%2ENET+Addins

The below is bookmarks I got from MZ-Tools page

The followings are the tips I learned while working on my add-in

  • Menu name for code window tab: “Easy MDI Document Window”
  • To display the pop up menu successfully
    • check if the command exist
    • Add the command if it doesn’t exist.
    • Code QueryStatus, otherwise, the command is not displayed, even though it is added.
  • Debugging: you need to run set-up in order to attach the process for debugging.
  • Copy string to Clipboard: Clipboard.SetDataObject(applicationObject.ActiveDocument.FullName, true);
  • opening a folder from c#
  • Getting the current document: string currentWindow = applicationObject.ActiveDocument.Name;
  • Get default source control provider (usually SourceSafe): applicationObject.SourceControl (from http://dotnet247.com/247reference/msgs/48/241224.aspx)

Events you should understand

  • QueryStatus: when you click on document tab and before it displays available context menu. The command name must be matched with the name you registered and QueryStatus must assign status value. Otherwise, the command will not be displayed on the context menu.

Often, you lose the command for the Add-in. Either you can install the add-in using .msi installation file or just run the registry (ReCreateCommands.reg).

The followings are a few tips I found while working on my first add-in project

  • hide objectbrowser window: DTE.Windows.Item(Constants.vsWindowKindObjectBrowser).Activate

At last, I found an example of closing all documents except the active one. This is the example

Public Sub CloseAllButCurrentWindow()
Dim i As Integer
sCurrWin As String = oVB.ActiveDocument.NameDebug.WriteLine(sCurrWin)
With oVB
On Error Resume Next
i = .Documents.Count To 1 Step 1
If .Documents.Item(i).Name sCurrWin Then
If Not
.Documents.Item(i).Saved Then

End If
End If
End With
End Sub

Colorized by: CarlosAg.CodeColorizerTroubleshootings

  • The add-in is installed, but does not appear on menu: A bit strange, but my add-in is not activated if the start-up option is checked on Add-in Manager. Disable start-up option and just check add-in, then it appears on context menu of document tab.
  • Remove the default smiley icon when you add your menu: chagne the default bitmap id 59 to 0

Command closeAllButThis = commands.AddNamedCommand(addInInstance,
, “Close All But this”, “Close all open documents but this”,
, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled);


52 if(connectMode == Extensibility.ext_ConnectMode.ext_cm_UISetup)

Why do I need the above check? I didn’t understand at the first time. ext_ConnectMode.ext_cm_UISetup status is only once when you install the add-in. So this prevents the addin from being installed multiple times. Anyway, this is not necessary when you are developing and debugging a add-in. So I removed for debugging purpose and compiles and run it. Now, TJ Dev Pack (the name of my add-in) is smiling in Tools menu. The add-in wizard generates codes that put the command in the [Tools] menu. Great!

And now I wants to put the command on Code window tabs’ context menu.

  • Use constant for Command name. It is so easy to make mistakes in command name if you use type the name each time, and if it happens, VS 2003 will complain that your addin cannot be loaded.
Writing a Visual Studio.Net 2003 Add-in

One thought on “Writing a Visual Studio.Net 2003 Add-in

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s