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
On the first page of the Extensibility Wizard, click
Next.
On the Select a Programming Language page,
click Create an Add-in using Visual C#, and then click
Next.
On the Select a Application Host page,
clear the Microsoft VSMacros IDE check box, and then
click Next.
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
Next.
On the Choose Add-in Options page, click
to select the following check box to create an item on the
Tools menu:
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
application loads:
I would like my Add-in to load when the host application starts.
Click Next.
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.
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
OK.
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
node.
Because setup projects are not included in the build
configuration by default, you must use one of the following methods to build
the solution:
Method 1: Right-click InsertDate, and then click
Build. Similarly, right-click
InsertDateTimeSetup, and then click
Build.
Method 2: To build the whole solution at once, click
Configuration Manager on the Build menu.
Click to select the Build check box for
InsertDateTimeSetup.
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
steps:
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
folder:
C:\InsertDateTime\InsertDateTimeSetup\Debug
Right-click InsertDateTimeSetup.msi,
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
Close.
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.
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
Customize.
On the Commands tab, click Addins in the
Categories list.
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
list.
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
shortcut.
Press BACKSPACE to delete the key
combination. Press the CTRL+SHIFT+BACKSPACE key combination. Because no
other command uses this keyboard shortcut, click
Assign.
In the Options dialog box, click
OK.
In the Customize dialog box, click
Close.
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.
Add-ins are compiled, and entries are written to the registry.
Therefore, whenever you change the add-in project, you must recompile, and
then reinstall the add-in.
When you try to build the project, you may receive one of
the following error messages:
unable to write to
output file
-or-
file in
use
To resolve this problem, right-click the setup project
in Solution Explorer, and then click Uninstall to remove
the add-in. You can the rebuild both projects, and reinstall the
add-in.