This article describes how to create a simple, compiled
add-in that inserts the current date and time at the insertion point. In this
article, you create and install an add-in project, load the add-in, and
integrate the add-in in the Visual Studio .NET or Visual Studio 2005 interface.
The following list outlines the recommended hardware,
software, network infrastructure, and service packs that you must have:
Microsoft Visual Studio .NET or Microsoft Visual Studio 2005
Microsoft Windows 2000 Professional, Microsoft Windows Server 2003, Microsoft Windows 2000
Server, Microsoft Windows XP Professional, Microsoft Windows XP Server with
the Microsoft .NET Framework
Create and Load Add-ins in Visual Studio .NET
Start Visual Studio .NET or Visual Studio 2005.
On the File menu, point to
New, and then click Project.
Under Project Types, expand
Other Projects, and then click Extensibility
Note In Visual Studio 2005, expand Other Projects Types under Project Types, and then click Extensibility.
Under Templates, click Visual
Studio .NET Add-in or Visual Studio Add-in.
In the Name text box, type
In the Location text box, type
C:\, and then click OK. This starts the
Complete the Steps in the Extensibility Wizard
On the first page of the Extensibility Wizard, click
On the Select a Programming Language page,
click Create an Add-in using Visual C#, and then click
On the Select a Application Host page,
clear the Microsoft VSMacros IDE check box, and then
Note In Visual Studio 2005, you do not have to click to clear the Microsoft VSMacros IDE check box.
On the Enter a Name and Description page,
type Insert Date and Time in the Name
text box. In the Description text box, type Inserts
the current date and time, and then click
On the Choose Add-in Options page, click
to select the following check box to create an item on the
Yes, create a 'Tools' menu item. By default this will cause the Add-in to load when the button is clicked unless the Add-in is set to load on startup of the host application.
On the Choose Add-in Options page, click
to select the following check box so that the add-in loads when the host
I would like my Add-in to load when the host application starts.
On the Choosing 'Help About' Information
page, click Next.
On the Summary page, click
Finish. This creates a solution with both an add-in project
and an add-in setup project.
Connect.cs File and Add Custom Actions
In Solution Explorer, double-click
Connect.cs, and then scroll through the file. Notice that
by default, Visual Studio .NET and Visual Studio 2005 insert the necessary code templates. For this
article, you only need to do the following:
In Solution Explorer, right-click
InsertDateTimeSetup, point to View, and then
click Custom Actions.
Right-click Custom Actions, and then click
Add Custom Action.
Click Application Folder, and then click
Click Primary output from
InsertDateTime(Active), and then click OK. Notice that
primary output appears in the Install, the
Commit, the Rollback, and the
Uninstall nodes under the Custom Actions
Build and Install the Add-in Project
Because setup projects are not included in the build
configuration by default, you must use one of the following methods to build
Method 1: Right-click InsertDate, and then click
Build. Similarly, right-click
InsertDateTimeSetup, and then click
Method 2: To build the whole solution at once, click
Configuration Manager on the Build menu.
Click to select the Build check box for
Press the CTRL+SHIFT+B key combination to build the
whole solution. A complete installation package is now available for InsertDateTime.
Install the add-in that you just built. To do this, follow these
Close all instances of Visual Studio .NET or Visual Studio 2005, and then
save any changes if you are prompted.
Open Windows Explorer, and then locate the following
and then click Install.
In the InsertDateTimeSetup dialog box,
click Next three times. Notice that a progress bar appears
while the service installs.
After the add-in is installed, click
Restart Visual Studio .NET or Visual Studio 2005.
Note After you restart Visual Studio .NET or Visual Studio 2005, the add-in is always loaded
until you remove it.
Add an Icon to the Toolbar
It is helpful, and also instructive, to integrate your
add-in more fully in the Visual Studio IDE. To do this, add an icon to the toolbar, and then associate the add-in
with a keyboard shortcut.
On the Tools menu, click
On the Commands tab, click Addins in the
Drag InsertDateTime to the active
toolbar, and then click Keyboard.
In the Show commands containing text box,
type insertdatetime. Notice that your add-in (InsertDateTime.Connect.InsertDateTime) appears in the
In the Press shortcut key(s) text box,
press the CTRL+SHIFT+RIGHT ARROW key combination. Notice that the
Shortcut currently used by text box notifies you that the
Edit.SizeControlRight command already uses this keyboard
Press BACKSPACE to delete the key
combination. Press the CTRL+SHIFT+BACKSPACE key combination. Because no
other command uses this keyboard shortcut, click
In the Options dialog box, click
In the Customize dialog box, click
In a text file, click InsertDateTime on
the toolbar. Notice that the text is inserted. Alternatively, you can also press
the CTRL+SHIFT+BACKSPACE key combination to insert the text.