Visual Studio.NET External Tools
The External Tools feature gives you the ability to add your own tools to the
Tools menu. This customization feature can make you more productive in Visual
In Visual Studio .NET, there is a Tools menu that contains, among other things,
a list of External Tools as shown below.
Everything between ActiveX Control Test Container through Spy++ is an external
tool that you can run right from your development environment. A tool can be any .com, .exe, .pif, or .bat file. The OLE/COM Object Viewer is one of my favorite tools that come with Visual Studio for looking at COM Interop issues. Notice the External Tools... menu item that allows you to configure your own external tools.
Add your own power tools
Note: This rest of this article will use Visual Studio .NET
2003. If you are using Visual Studio 2002, the location of some of the files
will be different.
As a simple example of what you can do with the External Tools feature, let's
add a menu option that will open up the Windows explorer in your project
directory. This is a great timesaver for performing file maintenance functions
that cannot normally be done through the Solution Explorer. Select External
Tools... from the Tools menu and the following window will display allowing you
to maintain your tools.
To add your new tool, do the following:
- Click the Add button and enter Windows Explorer as the title.
- Enter explorer.exe as the Command. (You may also use the ellipse to browse and
find it. Since it is located in your Windows directory you don't have to enter
the full path.)
- Click the right arrow button after Arguments and select ProjectDirectory from
the drop down list. This will add $(ProjectDir) to the text box.
- Click Apply and you're done. Now Windows Explorer will show up in your Tools
list and you have an easy way to go directly to your project's directory.
Argument List table
Here is the complete list of arguments that you can supply to your tool. These
are taken right out of the Visual Studio help file and presented here for your
convenience. When you use one of these in Arguments or Initial directory, Visual Studio will expand it to a file or directory name on your
hard drive. This feature is what makes External Tools so flexible.
||The complete file name of the current source (defined as drive +
path + file name); blank if a non-source window is active.
||The directory of the current source (defined as drive + path);
blank if a non-source window is active.
|Item File Name
||The file name of the current source (defined as file name); blank
if a non-source window is active.
||The file name extension of the current source.
||The current line position of the cursor in the editor
||The current column position of the cursor in the editor
||The current text (the word under the current cursor position, or a
single-line selection, if there is one).
||The complete file name of the target (defined as drive + path +
||The directory of the target.
||The file name of the target.
||The file name extension of the target.
||The directory of the current project (defined as drive + path).
|Project file name
||The file name of the current project (defined as drive + path +
||The directory of the current solution (defined as drive + path).
|Solution file name
||The file name of the current solution (defined as drive + path +
Open Dave's toolbox
Let's look at a couple more examples of things that I keep in my toolbox.
The Intermediate Language Disassembler (IlDasm, for short) is an excellent tool for learning the inner workings of .NET and a necessary tool for advanced debugging. It will display the information that goes into the manifest of your assembly and it will also show you the compiled output of your source code. You can add it to your Tools menu with the following settings:
- Title: ILDASM
- Command: C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\ildasm.exe
- Arguments: $(TargetPath)
When you do this, ILDASM will know to automatically open the correct output
assembly for whatever project you have selected in the Solution Explorer. For
example, suppose that you have a solution with two projects. One is a
Library Project that creates a DLL file and another project in the same
solution is a Windows Forms project that compiles to an EXE file. If
you highlight any item from the DLL project in Solution Explorer and
you run the ILDASM tool from the menu, it will automatically open the DLL
file. If instead you are anywhere in the Windows Form project, the same tool
will open the EXE file.
Summon the Visual Studio Command Prompt
The Visual Studio Command Prompt is where you get access to all the advanced
command line tools. Some examples are:
- sn.exe for creating strong name keys
- csc.exe and vbc.exe for compiling source
- al.exe for assembly linking
- gacutil.exe for managing the global assembly cache
- installutil.exe for installing Windows Services
The environment for using these command line tools is set up in the vsvars32.bat
file. Although the installation of Visual Studio will create a link to the
Visual Studio command prompt in your Start menu, it will leave you in a
starting directory that is not always useful. To run the default version
go to Start | All Programs | Microsoft Visual Studio .NET 2003 | Visual Studio
.NET Tools | Visual Studio .NET 2003 Command Prompt.
To start the command prompt in a more useful directory you can add it to your
External Tools menu with the following settings:
- Title: VS Command Prompt
- Command: cmd.exe
- Arguments: /k ("c:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat")
- Starting Directory: $(TargetDir)
Now when you run the Command Prompt through the Tools menu it will leave you in
the same directory where your exe and dll files are, which may be more
appropriate for running these command line tools.
There are few more things you can do with Tools.
You can define an Accelerator Key for your tool by
preceding a letter in the title with an ampersand. For example, a title of
&VS Command Prompt will make the V a hot key when the Tools menu is
active. You can add a Key Binding to make a shortcut key
to your tool. To do this, go to Tools | Options, highlight Keyboard in
Environment, scroll down to Tools.ExternalCommand (numbered 1 through 20) in
the list to the right. Once you highlight the name of the command that
corresponds to your tool, you can enter the keyboard command that will
run your tool. Press the Assign button to complete the keyboard
assignment. The completed process is shown below.
Getting back to the External Tools configuration windows, there are a couple of
more options. If you want to pass a different parameter to
your tool each time you run it, check off the Prompt for
Arguments option and Visual Studio will prompt you for the
If your tool writes to the standard output, you can have the output display to
the Visual Studio Output window instead of a separate DOS window by
checking off the Output to Window option. The
documentation says that this option is only available for .bat and
.com files, but I see that that it is also selected for the Dotfuscator tool
The tips presented in this article can save you the frustration of
fumbling around your hard drive looking for the directories and files that
belong to your project. External Tools give you easy access to
your developer tools, providing the "Integrated" features in the Integrated
development environment. For even more control over Visual Studio, look into
the Visual Studio macro features.
David Foderick is an independent software developer in Southern California and
owner of NetKnowledge, Inc (http://www.netknowledgenow.com). He specializes in
Microsoft development tools including .NET and Visual FoxPro. David is a
frequent speaker at the Los Angeles C# Developers Group and provides corporate
training on the .NET platform. He has a Bachelor's degree in Electrical
Engineering from the University of Minnesota and is a Microsoft Certified
Solution Developer in .NET. Please contact him at email@example.com.