Download this article discussion:
NUnit
used to write unit tests
ndoc
for creating code documentation
NAnt
used to build the solution
codesmith
for generating code
FxCop
for monitoring code
snippet Compiler for compiling small amounts of code
two different converter tools: ASP.net version converter and Visual Studio. NET Project Converter
regulator
used to generate regular expressions
. NET Reflector
used to parse assemblies
This article uses the following techniques:
. NET, C #, or Visual Basic. NET, visual Studio. NET
unless you use the best tool you can get, you can't expect to build a first-class application. In addition to well-known tools like Visual studio®.net, there are many small, less-known tools available from the. NET community. In this article, I'll introduce you to some of the best free tools available for. NET Development. I will guide you through a quick tutorial on how to use each of these tools-some tools can save you a minute in many cases, while others may radically change the way you write your code. Because I'm going to cover so many different tools in this article, I can't discuss each of these tools in detail, but you should know enough about each tool to determine which tools are useful to your project.
page Content
Snippet Compiler
Regulator
Codesmith
Build Custom Templates
NUnit
Write NUnit Test
FxCop
Lutz Roeder. NET Reflector
NDoc
NAnt
the actual operation of the NAnt
Conversion Tool
Summary
Snippet Compiler
Snippet Compiler is a small, Windows®-based application that you can use to write, compile, and run code. This tool is useful if you have a small code snippet and you do not want to create a complete Visual Studio. NET Project for it (and all files that accompany the project).
For example, suppose I want to show you how to get from Microsoft?. NET Framework to start another application. In snippet Compiler, I'll start by creating a new file that will create a small console application. You can create snippets of code inside the Main method of the console application, and that's exactly what I'm going to do here. The following code fragment demonstrates how to create a Notepad instance from the. NET Framework:
System.Diagnostics.Process proc = new System.Diagnostics.Process ();
Proc. Startinfo.filename= "notepad.exe";
Proc. Start ();
Proc. WaitForExit ();
of course the code fragment itself cannot compile, and this is where snippet Compiler comes in. Figure 1 shows this code example in Snippet Compiler.
Fig. 1 Snippet Compiler
To test the code fragment, just press the play button (the green triangle) and it will run in debug mode. The code fragment will generate a pop-up console application, and Notepad will be displayed. When you close Notepad, the console application is also closed.
in my own case, I was trying to create a small example for someone who asked me for help to discover that snippet Compiler was so valuable-if you don't use it, I usually have to create a new project to make sure that every part compiles and then sends the code snippet to the caller, and delete the item. Snippet Compiler makes the process easier and more enjoyable.
snippet Compiler is written by Jeff Key and can be downloaded from Http://www.sliver.com/dotnet/SnippetCompiler.
return to the top of the page
Regulator
regulator is the last one added to my list of first class tools. It is a very distinctive tool that makes it easy to build and test regular expressions. There is a renewed interest in regular expressions because they are well supported in the. NET framework. Regular expressions are used to define patterns in strings based on character, frequency, and character order. Their most common use is as a means of validating user input validity or as a way to find a string in a larger string-for example, to find a URL or e-mail address on a Web page.
regulator allows you to enter a regular expression and some input to run the expression against it. This way, before you implement the regular expression in your application, you can see what it will do and what kinds of matches it will return. Figure 2 shows the regulator with a simple regular expression.
The
document contains the regular expression-in this case, it is [0-9]*, which should match any number of numbers in a row. The box in the lower-right side contains input for the regular expression, and the bottom-left box shows the matches that the regular expression finds in the input. Writing and testing regular expressions in such a separate application is much easier than trying to handle them in your application.
One of the best features in regulator is the ability to search online regular expression libraries in regexlib.com. For example, if you enter the string "phone" in the search box, you will find more than 20 different regular expressions that can match the various phone numbers, including expressions for the UK, Australia, and many other phone numbers. Regulator is written by Roy Osherove and can be downloaded in http://royo.is-a-geek.com/regulator.
return to the top of the page
Codesmith
Codesmith is a template-based code generation tool that uses syntax similar to asp.net to generate any type of code or text. Unlike many other code generation tools, Codesmith does not ask you to subscribe to a particular application design or architecture. With Codesmith, you can generate anything that includes simple, strongly typed collections and complete applications.
When you build your application, you often need to do some specific tasks repeatedly, such as writing data access code or building a custom collection. Codesmith is especially useful at these times, because you can write templates to automate these tasks, not only to increase your productivity, but to automate the most tedious tasks. Codesmith comes with a number of templates, including templates for all. NET collection types and templates for building stored procedures, but the real power of the tool is the ability to create custom templates. To get you started, I'll give you a quick overview of how to build a custom template.
return to the top of the page
Build Custom Templates
codesmith templates are just a few text files that can be created in any text editor. Their only requirement is to save them with the. cst file name extension. The sample template that I am going to generate will accept a string and then generate a class based on that string. The first step in creating a template is to add a template header, which declares the language of the template, the target language, and the brief template description:
The next section of the
template is a property declaration, where you can declare a property that will be specified each time the template is run. As far as the template is concerned, the only property I want to use is a string, so the property declaration looks like this:
This property declaration causes the ClassName property to appear in the Codesmith property window so that it can be specified when the template is run. The next step is to actually generate the template body, which is very similar to encoding with ASP.net. You can view the body of the template in Figure 3. [Edit Update-6/16/2004: The code in Figure 3 has been updated to keep the multithreaded operation secure. ]
as you can see, the template accepts string input and generates a separate class using that class name. In the template body, use the same start and end tags as in asp.net. In the template, I just insert property values, but you can also use any type of. NET code inside those tags. After the template is complete, you can load it into codesmith by double-clicking it or opening it from the Codesmith application. Figure 4 shows the template that has been loaded into the codesmith.
you can see that the property on the left is exactly the property I declared in the template. If I type "Singletonclass" as the class name and click the Generate button, the class shown at the bottom of Figure 3 will be generated.
Codesmith is fairly easy to use and can produce some incredible results if applied correctly. One of the most common parts of a code-generation application is the data access layer. Codesmith includes a special assembly called Schemaexplorer that can be used from a table, stored procedure, or almost any other SQL Server. object to generate the template.
Codesmith is written by Eric J. Smith and can be downloaded in Http://www.ericjsmith.net/codesmith.
return to the top of the page
NUnit
NUnit is an open source unit test framework that is generated for the. NET Framework. NUnit enables you to test your application's specific functionality by writing tests in your favorite language. When you first write code, unit testing is a good way to test the functionality of your code, and it provides a way to test your application for regression. The NUnit application provides a framework for writing unit tests, as well as a graphical interface for running these tests and viewing the results.
return to the top of the page
Write NUnit Test
as an example, I will test the functionality of the Hashtable classes in the. NET framework to determine whether two objects can be added and then retrieved. My first step is to add a reference to the Nunit.framework assembly that gives me access to the properties and methods of the NUnit framework. Next, I'll create a class and mark it with the Testfixture property. This property enables NUnit to know that the class contains NUnit tests:
using System;
using System.Collections;
using Nunit.framework;
namespace Nunitexample
{
[Testfixture]
public class Hashtabletest {