Академический Документы
Профессиональный Документы
Культура Документы
Contents
TestDriven.NET
GhostDoc
Smart Paster
CodeKeep
PInvoke.NET
VSWindowManager PowerToy
WSContractFirst
VSMouseBindings
CopySourceAsHTML
Cache Visualizer
Wrapping It Up
Last year I wrote an article called ".NET Tools: Ten Must-Have Tools Every Developer Should Download Now" that
highlighted 10 freely available tools for the Microsoft add-ins as opposed to standalone tools. Visual Studio provides
a rich extensibility model that developers at Microsoft and in the community have taken advantage of to provide a Current Issue
host of quality add-ins. Some add-ins contribute significant how-did-I-live-without-this functionality, while others just
help you automate that small redundant task you constantly find yourself performing.
10 Must-Have Add-Ins
TestDriven.NET
GhostDoc
Paster
CodeKeep
PInvoke.NET
VSWindowManager PowerToy
WSContractFirst
VSMouseBindings
CopySourceAsHTML
Cache Visualizer
In this article, I introduce you to some of the best Visual Studio add-ins available today that can be downloaded for Browse All MSDN Magazines
free. I walk through using each of the add-ins, but because I am covering so many I only have room to introduce you
to the basic functionality. Each of these add-ins works with Visual Studio .NET 2003 and most of them already have
versions available for Visual Studio 2005. If a Visual Studio 2005 version is not available as of the time of this writing, it
should be shortly.
TestDriven.NET
Test-driven development is the practice of writing unit tests before you write code, and then writing the code to
make those tests pass. By writing tests before you write code, you identify the exact behavior your code should
exhibit and, as a bonus, at the end you have 100 percent test coverage, which makes extensive refactoring possible.
NUnit gives you the ability to write unit tests using a simple syntax and then execute those tests one by one or
altogether against your app. If you are using Visual Studio Team System, you have unit testing functionality built into
the Visual Studio IDE. Before the Visual Studio Team System, there was TestDriven.NET, an add-in that integrates
NUnit directly into the Visual Studio IDE. Using a non-Team System version of Visual Studio 2005 or Visual Studio
.NET 2003, is, in my opinion, still the best solution available.
TestDriven.NET adds unit testing functionality directly to the Visual Studio IDE. Instead of writing a unit test,
switching over to the NUnit GUI tool, running the test, then switching back to the IDE to code, and so on, you can do
it all right in the IDE.
GhostDoc
XML comments are invaluable tools when documenting your application. Using XML comments, you can mark up
your code and then, using a tool like nDoc, you can generate help files or MSDN-like Web documentation based on
those comments. The only problem with XML documentation is the time it takes to write it you often end up writing
similar statements over and over again. The goal of GhostDoc is to automate the tedious parts of writing XML
comments by looking at the name of your class or method, as well as any parameters, and making an educated guess
as to how the documentation should appear based on recommended naming conventions. This is not a replacement
for writing thorough documentation of your business rules and providing examples, but it will automate the mindless
part of your documentation generation.
For instance consider the method shown here:
Copy Code
private void SavePerson(Person person)
{
After installing GhostDoc, you can right-click on the method declaration and choose Document this. The following
comments will then be added to your document:
Copy Code
/// <summary>
/// Saves the person.
/// </summary>
/// <param name="person">Person.</param>
private void SavePerson(Person person)
{
As you can see, GhostDoc has automatically generated a summary based on how the method was named and has
also populated the parameter comments. Don't stop hereyou should add additional comments stating where the
person is being saved to or perhaps give an example of creating and saving a person. Here is my comment after
adding some additional information by hand:
Copy Code
/// <summary>
/// Saves a person using the configured persistence provider.
/// </summary>
/// <param name="person">The Person to be saved</param>
private void SavePerson(Person person)
{
Adding these extra comments is much easier since the basic, redundant portion is automatically generated by
GhostDoc. GhostDoc also includes options that allow you to modify existing rules and add additional rules that
determine what kind of comments should be generated.
GhostDoc was written by Roland Weigelt and can be downloaded fromwww.roland-weigelt.de/ghostdoc.
Smart Paster
Strings play a large role in most applications, whether they are comments being used to describe the behavior of the
system, messages being sent to the user, or SQL statements that will be executed. One of the frustrating parts of
working with strings is that they never seem to paste correctly into the IDE. When you are pasting comments, the
strings might be too long or not aligned correctly, leaving you to spend time inserting line breaks, comment
characters, and tabbing. When working with strings that will actually be concatenated, you have to do even more
work, usually separating the parts of the string and inserting concatenation symbols or using a string builder.
The Smart Paster add-in helps to limit some of this by providing a number of commands on the right-click menu that
let you paste a string from the clipboard into Visual Studio using a certain format. After installing Smart Paster, you
will see the new paste options available on the right-click menu (see Figure 3).
You can copy and paste this into Visual Studio using the Paste As | Comment option, and you would get the
following:
Copy Code
//To update a person record a user must be a member of the customer
//service group or the manager group. After the person has been updated
//a letter needs to be generated to notify the customer of the
//information change.
The correct comment characters and carriage returns are automatically inserted (you can configure at what length to
insert a character return). If you were inserting this text without the help of Smart Paster, it would paste as one long
line, forcing you to manually add all the line breaks and comment characters. As another example, let's say you have
the following error message that you need to insert values into at run time:
Copy Code
You do not have the correct permissions to perform <insert action>.
You must be a member of the <insert group> to perform this action.
Using the Paste As | StringBuilder command, you can insert this string as a StringBuilder into Visual Studio. The
results would look like this:
Copy Code
StringBuilder stringBuilder = new StringBuilder(134);
stringBuilder.AppendFormat(
@"You do not have the correct permissions to ");
stringBuilder.AppendFormat(
@"perform <insert action>. You must be a member of ");
stringBuilder.AppendFormat(
@"the <insert group> to perform this action.");
It would then simply be a matter of modifying the code to replace the variables sections of the string:
Copy Code
StringBuilder stringBuilder = new StringBuilder(134);
stringBuilder.AppendFormat(
@"You do not have the correct permissions to ");
stringBuilder.AppendFormat(
@"perform {0}. You must be a member of ", action);
stringBuilder.AppendFormat(
@"the {0} to perform this action.", group);
Smart Paster is a time-saving add-in that eliminates a lot of the busy work associated with working with strings in
Visual Studio. It was written by Alex Papadimoulis and is available from
weblogs.asp.net/alex_papadimoulis/category/5341.aspx.
CodeKeep
Throughout the process of software development, it is common to reuse small snippets of code. Perhaps you reuse
an example of how to get an enum value from a string or a starting point on how to implement a certain pattern in
your language of choice.
Visual Studio offers some built-in functionality for working with code snippets, but it assumes a couple of things.
First, it assumes that you are going to store all of your snippets on your local machine, so if you switch machines or
move jobs you have to remember to pack up your snippets and take them with you. Second, these snippets can only
be viewed by you. There is no built-in mechanism for sharing snippets between users, groups, or the general public.
This is where CodeKeep comes to the rescue. CodeKeep is a Web application that provides a place for people to
create and share snippets of code in any language. The true usefulness of CodeKeep is its Visual Studio add-in, which
allows you to search quickly through the CodeKeep database, as well as submit your own snippets.
After installing CodeKeep, you can search the existing code snippets by selecting Tools | CodeKeep | Search, and then
using the search screen shown in Figure 4.
PInvoke.NET
API calls within the .NET Framework. One of the hard parts of using P/Invoke is determining the method signature
you need to use; this can often be an exercise in trial and error. Sending incorrect data types or values to an
unmanaged API can often result in memory leaks or other unexpected results.
PInvoke.NET is a wiki that can be used to document the correct P/Invoke signatures to be used when calling
unmanaged Win32 APIs. A wiki is a collaborative Web site that anyone can edit, which means there are thousands of
signatures, examples, and notes about using P/Invoke. Since the wiki can be edited by anyone, you can contribute as
well as make use of the information there.
While the wiki and the information stored there are extremely valuable, what makes them most valuable is the
PInvoke.NET Visual Studio add-in. Once you have downloaded and installed the PInvoke.NET add-in, you will be able
to search for signatures as well as submit new content from inside Visual Studio. Simply right-click on your code file
and you will see two new context items: Insert PInvoke Signatures and Contribute PInvoke Signatures and Types.
You then simply need to write a call to this method and your computer will be beeping in no time.
The PInvoke.NET wiki and Visual Studio add-in take away a lot of the pain and research time sometimes involved
when working with the Win32 API from managed code. The wiki can be accessed at www.pinvoke.net, and the add-in
can be downloaded from the Helpful Tools link found in the bottom-left corner of the site.
VSWindowManager PowerToy
The Visual Studio IDE includes a huge number of different Windows, all of which are useful at different times. If you
are like me, you have different window layouts that you like to use at various points in your dev work. When I am
writing HTML, I like to hide the toolbox and the task list window. When I am designing forms, I want to display the
toolbox and the task list. When I am writing code, I like to hide all the windows except for the task list. Having to
constantly open, close, and move windows based on what I am doing can be both frustrating and time consuming.
Visual Studio includes the concept of window layouts. You may have noticed that when you start debugging, the
windows will automatically go back to the layout they were in the last time you were debugging. This is because
Visual Studio includes a normal and a debugging window layout. Wouldn't it be nice if there were additional layouts
you could use for when you are coding versus designing? Well, that is exactly what VSWindowManager PowerToy
does.
After installing VSWindowManager PowerToy, you will see some new options in the Window menu as shown in
Figure 7.
WSContractFirst
Visual Studio makes creating Web services deceptively easy You simply create an .asmx file, add some code, and you
are ready to go. ASP.NET can then create a Web Services Description Language (WSDL) file used to describe behavior
and message patterns for your Web service.
There are a couple problems with letting ASP.NET generate this file for you. The main issue is that you are no longer
in control of the contract you are creating for your Web service. This is where contract-first development comes to
the rescue. Contract-first development, also called contract-driven development, is the practice of writing the contract
(the WSDL file) for your Web service before you actually write the Web service itself. By writing your own WSDL file,
you have complete control over how your Web service will be seen and used, including the interface and data
structures that are exposed.
Writing a WSDL document is not a lot of fun. It's kind of like writing a legal contract, but using lots of XML. This is
where the WSContractFirst add-in comes into play. WSContractFirst makes it easier to write your WSDL file, and will
generate client-side and server-side code for you, based on that WSDL file. You get the best of both worlds: control
over your contract and the rapid development you are used to from Visual Studio style services development.
The first step to using WSContractFirst is to create your XML schema files. These files will define the message or
messages that will be used with your Web services. Visual Studio provides an easy-to-use GUI interface to define
your schemasthis is particularly helpful since this is one of the key steps of the Web service development process.
Once you have defined your schemas you simply need to right-click on one of them and choose Create WSDL
Interface Description. This will launch the Generate WSDL Wizard, the first step of which is shown in Figure 8.
VSMouseBindings
Your mouse probably has five buttons, so why are you only using three of them? The VSMouseBindings power toy
provides an easy to use interface that lets you assign each of your mouse buttons to a Visual Studio command.
VSMouseBindings makes extensive use of the command pattern. You can bind mouse buttoms to various commands,
such as open a new file, copy the selected text to the clipboard, or just about anything else you can do in Visual
Studio. After installing VSMouseBindings you will see a new section in the Options dialog box called
VsMouseBindings. The interface can be seen in Figure 10.
CopySourceAsHTML
Code is exponentially more readable when certain parts of that code are differentiated from the rest by using a
different color text. Reading code in Visual Studio is generally much easier than trying to read code in an editor like
Notepad.
Chances are you may have your own blog by now, or at least have spent some time reading them. Normally, when
you try to post a cool code snippet to your blog it ends up being plain old text, which isn't the easiest thing to read.
This is where the CopySourceAsHTML add-in comes in to play. This add-in allows you to copy code as HTML,
meaning you can easily post it to your blog or Web site and retain the coloring applied through Visual Studio.
After installing the CopySourceAsHTML add-in, simply select the code you want to copy and then select the Copy
Source as HTML command from the right-click menu. After selecting this option you will see the dialog box shown in
Figure 11.
After you select Copy As HTML and configure the HTML to include line numbers, this code will look likeFigure 12 in
the browser. Anything that makes it easier to share and understand code benefits all of us as it means more people
will go to the trouble of sharing knowledge and learning from each other.
CopySourceAsHTML was written by Colin Coller and can be downloaded fromwww.jtleigh.com/CopySourceAsHtml.
Cache Visualizer
Visual Studio 2005 includes a new debugging feature called visualizers, which can be used to create a human-
readable view of data for use during the debugging process. Visual Studio 2005 includes a number of debugger
visualizers by default, most notably the DataSet visualizer, which provides a tabular interface to view and edit the data
inside a DataSet. While the default visualizers are very valuable, perhaps the best part of this new interface is that it is
completely extensible. With just a little bit of work you can write your own visualizers to make debugging that much
easier.
While a lot of users will write visualizers for their own custom complex types, some developers are already posting
visualizers for parts of the Framework. I am going to look at one of the community-built visualizers that is already
available and how it can be used to make debugging much easier.
The ASP.NET Cache represents a collection of objects that are being stored for later use. Each object has some
settings wrapped around it, such as how long it will be cached for or any cache dependencies. There is no easy way
while debugging to get an idea of what is in the cache, how long it will be there, or what it is watching. Brett Johnson
saw that gap and wrote Cache Visualizer to examine the ASP.NET cache.
Once you have downloaded and installed the visualizer you will see a new icon appear next to the cache object in
your debug windows, as shown in Figure 13.
Wrapping It Up
While this article has been dedicated to freely available add-ins, there are also a host of add-ins that can be
purchased for a reasonable price. I encourage you to check out these other options, as in some cases they can add
some tremendous functionality to the IDE. This article has been a quick tour of some of the best freely available add-
ins for Visual Studio. Each of these add-ins may only do a small thing, but together they help to increase your
productivity and enable you to write better code.
James Avery runs his own .NET consulting practice, Infozerk Inc. He has written a number of books
and articles, his most recent book is Visual Studio Hacks (O'Reilly, 2005). You can e-mail him at
javery@infozerk.com and read his blog.
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback