Ten essential tools that each developer should download now
Release Date: 7/20/2004
| Update Date: 7/20/2004
This article has increased new information since the release.
See the editing update below.
This article discusses:
• NUnit for writing unit tests • NDOC for creating code document • NDOC for generating solutions • CODESMITH for generating code • FXCOP for monitoring code • Snippet Compiler for compiling a small number of code • Two Different converter tools: ASP.NET version converter and Visual Studio .NET project converter • REGULATOR used to generate regular expressions • .NET Reflector for analyzing assemblies
This article uses the following technique:
.NET, C # or Visual Basic .NET, Visual Studio .NET
Unless you use the best tool you get, you can't expect to generate first-class applications. In addition to famous tools such as Visual Studio®.Net, you can also get many small, less known tools from the .NET community. In this article, I will introduce you to some of the best-free tools for .NET development. I will guide you to complete a quick tutorial about how to use each tool - some tools can save you more than one minute, while others may completely change your way of writing code. Because I want to introduce such different tools in this article, I can't discuss each of the tools in detail, but you should learn enough information about each tool to determine which tool is useful for your project.
This page
Snippet CompilerRegulatorCodesmith Generates Custom Template NUnit Writing NUNIT Test FxCoplutz RoEDER's .NET ReflectorndOcnant actually running NANT conversion tool summary
Snippet Compiler
Snippet Compiler is a Windows®-based small application that you can write, compile and run code through it. If you have a smaller code segment, you don't want to create a complete Visual Studio .NET project (and all files accompanying the project), the tool will be useful.
For example, suppose I want to show you how to start another application from the Microsoft® .NET framework. In Snippet Compiler, I will start with newly built a file that can create a small console application. You can create a code snippet inside the main method of the console application, and this is exactly what I want to do here. The following code snippet 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 snippet cannot be compiled, and this is the land of Snippet Compiler. Figure 1 shows this code example in the Snippet Compiler.
Figure 1 SNIPPET COMPILER
To test the code snippet, you only need to press the Play button (green triangle), it will run in debug mode. This code snippet will generate a pop-up console application and will display a notepad. This console application will also close when you turn off the notepad.
I personally, I found that Snippet Compiler was so valuable when trying to create a small example for someone who helped me. - If I don't use the tool, I usually have to create a new project to make sure each The part can be compiled, and then the code snippet is sent to the help and delete the item. Snippet Compiler makes this process easier and more enjoyable. Snippet Compiler is written by Jeff Key and can be downloaded from http://www.sliver.com/dotnet/snippetCompiler.
Regulator
Regulator is the last addition to my head and other tool list. It is a very distinctive tool that makes it easy to generate and test regular expressions. People researchers regular expressions because they are well supported in the .NET framework. Regular expressions are used to define patterns in strings based on characters, frequencies, and character sequences. Their most common use is a means of verifying user input validity or as a method of looking up a string in a larger string - for example, looking for a URL or email address on a web page.
Regulator allows you to enter a regular expression and some inputs that run the expression. This way, before implementing the regular expression in the application, you can understand what effect it will generate and which type of matching item will return. Figure 2 shows the Regulator with a simple regular expression.
The document contains the regular expression - in this example, it is [0-9] *, which should match the number of numbers in a row. In the lower right side contain inputs for this regular expression, and the lower left side of the box displays the matching item found in the input content. Writing and testing regular expressions in such separate applications, which is much easier than attempts to handle them in your application.
One of the best features in Regulator is to search online regular expressions in regexlib.com. For example, if you enter a string "Phone" in the search box, you will find different regular expressions that match various phone numbers, including expressions and many other phone numbers for the UK, Australia. Regulator is written by Roy Osherove and can be downloaded at http://royo.is-a-geek.com/regulator.
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 require you to subscribe to a specific application design or architecture. Using CODesmith, you can generate anything that includes a simple intensive integer and full application.
When you generate an application, you often need to repeat some specific tasks, such as writing a data access code or generate a custom set. CODesmith is especially useful because you can write templates to automate these tasks, not only improve your productivity, but also automatically complete the most boring tasks. CoDesmith has many templates, including templates corresponding to all .NET collection types, and templates for generating stored procedures, but the truly power of this tool is to create custom templates. In order for you to get started, I will quickly introduce how to generate a custom template.
Generate custom templates
The CodeSmith template is just some text files that can be created in any text editor. The only requirement is to save them with the .CST file extension. I will generate the sample template will accept a string and then generate a class based on the string. The first step in creating a template is to add a template head, which can declare the language, target language, and a brief template for templates:
<% @ CODETEMPLATE LANGUAGE = "C #"
TargetLanguage = "C #"
Description = "car template"%>
The next part of the template is the attribute statement, where you can declare the properties that will be specified at the template each time. For this template, the only property I want to use is just a string, so the attribute statement is as follows:
<% @Property name = "classname" type = "string" category = "context" description = "class name"%>
This attribute declaration will cause the className property in the CodeSmith property window so that it can be specified at the template runtime. The next step is to actually generate a template main body, which is very similar to encoding with ASP.NET. You can view the main body of the template in Figure 3. [Edit Update - 6/16/2004: The code in Figure 3 has been updated so that the multi-threaded operation is safe. ]
As you can see, this template accepts string input and uses this class name to generate a separate class. In the template body, use the same start and end tags as in ASP.NET. In this template, I just insert the attribute value, but you can also use any type of .NET code inside these tags. After this template is complete, you can load it to CODesmith by double-clicking on it or open it from the CodeSmith application. Figure 4 shows the template that has been loaded into CODesmith.
You can see the properties on the left is the properties I declared in this template. If I entered "Singletonclass" as class name, and click the Generate button, the category of the bottom display of FIG. 3 will be generated.
CODesmith is used quite easy. If it is possible to properly, some incredible results can be generated. One of the most common parts of the code-generated application is the data access layer. Codesmith includes a special assembly called SchemaExplorer, which can be used to generate templates from tables, stored procedures, or almost any other SQL Server? Object.
CODesmith is written by Eric J. Smith and can be downloaded at http://www.ericjsmith.net/codesmith.
NUnit
NUNIT is an open source unit test framework generated for .NET framework. NUnit allows you to write tests with your favorite language to test your specific features. When you write code for the first time, unit test is a good way to test code functions, which also provides a method of regulating the application. The NUnit application provides a framework for writing unit tests, as well as a graphical interface running these tests and viewing results.
Write a NUNIT test
As an example, I will test the function of the HashTable class in the .NET framework to determine if two objects can be added and these objects are retrieved. My first step is to add a reference to the NUNIT.FRAMEWORK assembly, which will give me access to the properties and methods of the NUnit framework. Next, I will 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 {
Public hashtabletest () {
}
}
}
Next, I will create a method and tag it with the [Test] property so that NUnit knows that this method is a test. Then, I will build a HashTable and add two values to it, and use the assert.Arequal method to see if I can retrieve the same value as the value added to the HashTable, as shown in the following code: [Test]
Public void hashtableaddtest ()
{
Hashtable ht = new hashtable ();
Ht.Add ("Key1", "Value1");
HT.Add ("Key2", "Value2");
Assert.Arequal ("Value1", HT ["Key1"], "Wrong Object Returned!");
Assert.Arequal ("Value2", HT ["Key2"], "Wrong Object Returned!");
}
This will confirm that I can first add a value to the HashTable and then retrieve the corresponding value - this is a very simple test, but it is possible to show the function of NUnit. There are many test types and various Assert methods, which can be used to test each part of the code.
To run this test, I need to generate a project, open the generated assembly in the NUnit application, and then click the Run button. Figure 5 shows the result. When I saw the big green stripe, I had an excitement and dizzy feel because it let me know that the test has passed. This simple example shows how convenient and powerful NUnit and unit tests. Since you can write a saved unit test, you can re-run the unit test whenever you change the code, you can not only detect the defects in the code, but eventually you can deliver a better application.
Figure 5 NUnit
NUNIT is an open source project and can be downloaded from http://www.nunit.org. There is also an excellent NUNIT Visual Studio .NET Add 2, which allows you to run unit testing directly from Visual Studio. You can find it at http://sourceforge.net/projects/nunitaddin. For more information on NUNIT and its status in test-driven development, please refer to article "Test-Driven C #: Improve The Design and Flexibility of Your Project with extreme programming techniques" (MSDN ® Magazine) April 2004).
FXCOP
The .NET framework is very powerful, which means that there is a great possibility of creating an excellent application, but there is also a possibility of creating inferior programs. FXCOP is one of the tools that help to create a better application. The method it uses is to analyze the assembly and use some different rules to check if it meets these rules. FXCOP comes with a fixed number of rules created by Microsoft, but you can also create and include your own rules. For example, if you decide that all classes should have a default constructor without any parameters, you can write a rule to ensure that each class of the assembly has a constructor. In this way, no matter who write the code, you will get a certain degree of consistency. If you need more information about creating custom rules, see the Bugslayer column article for this topic (MSDN ® Magazine, June 2004).
So let's take a look at the actual FXCOP and look at which errors in the NUNITEXAMPLE program I have been dealing with. When you open FXCOP, you first need to create an FXCOP project and add the assembly you want to test. After adding the assembly to the project, you can press Analyze and FXCOP will analyze the assembly. The errors and warnings found in the assembly are shown in Figure 6. FXCOP found several questions in my assembly. You can double-click an error to view details, including rule instructions, and where you can find more information. (You can do a interesting thing is to run FXCOP on the framework set and see what happened.)
FXCOP can help you create better, more consistent code, but it is unable to compensate for poor application design or very simple and poor programming. FXCOP cannot replace the peer code check, but because it can capture a lot of errors before performing code check, you can spend more time to solve serious problems without having to worry about naming conventions. FXCOP is developed by Microsoft and can be downloaded from http://www.gotdotnet.com/team/fxcop.
Lutz Roeder's .NET Reflector
The next an essential tool is called .Net Reflector, it is a class browser and an anti-compiler to analyze the assembly and display all of its secrets to you. The .NET framework introduces the reflection concept that can be used to analyze any .NET-based code (whether it is a single or complete assembly). Reflection can also be used to retrieve information about the various classes, methods, and attributes included in a particular program. Using the .NET Reflector, you can browse the class and method of the assembly, you can analyze the Microsoft Intermediate Language (MSIL) generated by these classes and methods, and can be refactored to compile these classes and methods and view C # or Visual Basic ® .NET. Equivalent classes and methods.
In order to demonstrate the mode of work of .Net Reflector, I will load and analyze the NUNITEXAMPLE assembly that has already been displayed in front. Figure 7 shows the assembly loaded in .NET Reflector.
Figure 7 NUNITEXAMPLE assembly
Inside the .NET Reflector, there are various tools that can be used to further analyze the assembly. To view MSIL constituting a method, click this method and select DisasseMbler from the menu.
In addition to being able to view MSIL, you can also view the C # form of the method by selecting Decompiler under the Tools menu. You can view this method in the form of Visual Basic .NET or Delphi by changing your choice under the Languages menu. The following is the code generated by .NET Reflector:
Public void hashtableaddtest ()
{
Hashtable hashtable1;
Hashtable1 = new hashtable ();
Hashtable1.add ("key1", "value1");
Hashtable1.add ("key2", "value2");
Assert.Arequal ("Value1", Hashtable1 ["Key1"],
"WRONG OBJECT RETURNED!");
Assert.Arequal ("Value2", Hashtable1 ["Key2"],
"WRONG OBJECT RETURNED!");
}
The previous code looks like I actually written for this method. The following is the actual code in the assembly:
Public void hashtableaddtest ()
{
Hashtable ht = new hashtable ();
Ht.Add ("Key1", "Value1");
HT.Add ("Key2", "Value2");
AskERT.Areequal ("Value1", HT ["Key1"],
"WRONG OBJECT RETURNED!");
AskERT.Areequal ("Value2", HT ["Key2"],
"WRONG OBJECT RETURNED!");
}
Although there are some small differences in the above code, they are functionally identical.
Although this example is a good way to display actual code and anti-compile code, in my opinion, it does not mean the best use of .NET Reflector - Analysis .NET Framework assembly and method. The .NET framework provides many different ways to perform similar operations. For example, if you need to read a set of data from XML, there are a variety of ways to use XMLDocument, XPathnavigator or XmlReader to complete the work. By using the .NET Reflector, you can view what Microsoft uses what works when writing the data set, or see what work when they read data from the configuration file. .NET REFLEctor or an excellent way to learn the best implementation policies: Create objects such as httphandlers or configuration handler, because you can understand how the Microsoft Workgroup actually generates these objects in the framework.
.NET Reflector is written by Lutz Roeder and can be downloaded from http://www.aisto.com/roeder/dotnet.
NDOC
Write code documentation is almost always a fearful task. What I said is not an early design document, or even more detailed design documents; I am talking about the various methods and properties on the record class. The NDOC tool can use reflection to analyze the assembly, and use XML generated from C # XML annotations to generate documentation for code. XML comments apply only to C #, but there is a Visual Studio .NET Power Toy called VBcommenter, which can do a similar job for Visual Basic .NET. In addition, the next version of Visual Studio will support XML annotations for more languages.
When using NDOC, you are still writing code technology documents, but you have completed documentation in the process of writing code (in XML annotations), and this is easier to endure. When using NDOC, the first step is to open an XML annotation function for your assembly. Right-click the item and select Properties | Configuration Properties | Build, and enter the path to save the XML file in the XML Documentation File option. When the project is generated, an XML file is created, which contains all XML comments. Below is a method of writing a document with XML in the NUnit example:
///
/// THIS TEST ADDS A Number of Values To The Hashtable Collection
/// and the retrieves those value and checks if the match.
/// summary>
[TEST]
Public void hashtableaddtest () {
//Method Body Here
}
The XML document data on this method will be extracted and saved in the XML file, as shown below:
AND THEN RETRIEVES Those Values and Checks if the match. summary>
member>
NDOC uses reflection to examine your assembly and then read XML in this document and match them. NDOC uses this data to create any number of different document formats, including HTML Help File (CHM). After generating an XML file, the next step is to load the assembly and the XML file into NDOC so that they can be processed. This work can be easily done by opening NDOC and clicking the Add button.
After loading the assembly and XML file into NDOC and uses the available property range custom output, click the Generate button to start the process of generating document data. Using the default properties, NDOC can generate some very attractive and practical .html and .html and .chm files, which automatically completes the original very boring task in a quick and effective way.
NDOC is an open source project and can be downloaded from http://ndoc.sourceforge.net.
Nant
Nant is a .NET-based generating tool that is different from the current version of Visual Studio .net, which makes it easy to create a generation process for your project. When you have a large number of developers engaged in a single project, you cannot generate from a single user's seat. You also don't want to manually generate this project regularly. You are more willing to create an automatic generation process running every night. Nant allows you to generate solutions, copy files, run NUnit test, send emails, and so on. Unfortunately, NANT lacks a beautiful graphical interface, but it does have a console application and XML file that can specify which tasks should be completed during the generation process. Note that MSBuild (New Generate Platform belonging to Visual Studio 2005) is prepared for each robust generation scheme and is driven in a similar manner based on XML-based project files.
Real running nant
In this example, I will create a NANT version file for the NUNITEXAMPLE solution created in front. First, I need to create an XML file with the .build extension, put it in my root directory, then add an XML declaration to the top of the file. The first tag I need to add to the file is Project tag:
XML Version = "1.0"?>
provject>
The item standard is also used to set the project name, the default target, and the base directory. The Description tag is used to set a short description of the project.
Next, I will add a Property tag that can be used to store the settings to a single location (then can access the location from any location in the file). In this example, I will create an attribute called debug, I can set it to True or false to reflect whether I want to compile the project under debug configuration. (Finally, this particular attribute does not really affect how to generate the project; it is just a variable you set, when you really determine how to generate the project, you will read the variable.) Next, I need to create a Target tag. . A project can contain multiple Targets specified at NANT runtime. If you do not specify a Target, use the default target (I set the target of the Project element). In this example, the default target is build. Let us observe the Target element, which will contain most of the generated information:
target>
During the target element, I will set the name of the target to build and create a description of what works will be done. I will also create a CSC element that specifies the data that should be passed to the CSC C # compiler. Let's take a look at the CSC element:
Debug = "$ {debug}"> references> Sources> csc> First, I have to set the Target of the CSC element. In this example, I will create a .dll file, so I set the target to library. Next, I have to set up the Output of the CSC element, which is the location where the .dll file will be created. Finally, I need to set the debug property that determines whether it is compiled in debugging. Because I created an attribute used to store this value in front, I can use the following string to access the value of this property: $ {debug}. The CSC element also contains some child elements. I need to create two elements: References elements will tell NANT which assemblies need to be referenced for the project, Sources elements tell NANT which files are to be included in the generation process. In this example, I reference the NUnit.framework.dll assembly and contain the HashTableTest.cs file. A complete generated file is shown in Figure 8. (You should also create a clean target for deleting the generated file, but for the sake of simplicity, I have omitted it.) To generate this file, I need to go to the root directory of my project (generated files here), then execute nant.exe from this location. If the generation is successful, you can find a .dll and .pdb file in the bin directory of the application. Although using Nant is not as simple as in Visual Studio, it is still a very powerful tool that can be used to develop the generated process running according to the automatic plan. Nant also includes useful features, such as running unit testing or copying additional files (these features are not supported by the current Visual Studio generation process). Nant is an open source project and can be downloaded from http://nant.sourceforge.net. Conversion tool I have put two separate tools together in the title "Conversion Tool". These two tools are very simple, but it may be very useful. The first tool is an ASP.NET version converter that can be used to convert the version of the ASP.NET (virtual directory in it runs). The second tool is Visual Studio Converter, which can be used to convert project files from Visual Studio .NET 2002 to Visual Studio .NET 2003. When IIS processing request, it views the extension of the requested file, and then delegate the request to the ISAPI extension or handles the request based on the extension mapping of the Web site or virtual directory. This is the working mode of ASP.NET; will register extension mappings for all ASP.NET extensions and guide these extensions maps. This way is perfect, unless you install ASP.NET 1.1 - it will upgrade the extension map to the new version of ASPNET_ISAPI.dll. This will cause errors when the application generated on ASP.NET 1.0 is running. To resolve this issue, you can re-convert all extended mappings to the version of ASPNET_ISAPI.DLL, but because there are 18 extension mappings, it will be boring manually. This is the time when the ASP.NET version converter can work. Using this small utility, you can convert the version of the .NET framework used by any single ASP.NET application. Figure 9 ASP.NET version converter Figure 9 shows the actual ASP.NET version converter. Its method is very simple, just select the corresponding application, then select the .NET framework version you want the application. This tool will then use the ASPNET_REGIIS.exe command line tool to convert the application to the framework of the selected version. This tool will become more useful as the future version of the ASP.NET and .NET framework. The ASP.NET version converter is written by Denis Bauer and can be downloaded from http://www.denisbauer.com/nettools/aspnetversionswitcher.aspx. Visual Studio .NET Project Converter (see Figure 10) Very similar to the ASP.NET version converter, which differs from the version of the Visual Studio project file. Although there is only a small difference between the .NET framework 1.0 and 1.1 editions, once the project file is converted from Visual Studio .NET 2002 to Visual Studio .NET 2003, it will not be able to convert it back. Although this may not be a problem most of the time (because there is almost no destructive change between .NET Framework 1.0 and version 1.1 version), you may need to convert the project back in some moments. The converter can convert any solution or project file from Visual Studio 7.1 (Visual Studio .NET 2003) to Visual Studio 7.0 (Visual Studio .NET 2002) and reverse conversions when necessary. Figure 10 Visual Studio .NET Project Converter The Visual Studio .NET project converter is written by Dacris Software. This tool can be downloaded from http://www.codeproject.com/macro/vsconvert.asp. summary This article introduces the above tools in the way, but I have tried to attempt to provide you with sufficient information to provoke your curiosity. I believe this article has made you realize several free tools to some extent, you can start using these tools immediately to write better items. At the same time, I will also urge you to ensure that you have all other suitable tools, whether the latest version of Visual Studio, powerful computer or free utility. Having a suitable tool will make everything bigger. James Avery is a consultant using .NET and other Microsoft technology. He has written a lot of books and articles, his latest book is "ASP.NET Setup and Configuration Pocket Reference" (Microsoft Press, 2003). You can send emails to him through javery@infozerk.com, and read his network diary at http://www.dotavery.com/blog. This article is taken from MSDN Magazine 2004 July 2004. Ten Must-Have Tools Every Developer Should Download Now James avery This Article Discusses: NUnit to write unit tests NDoc to create code documentation NAnt to build your solutions CodeSmith to generate code FxCop to police your code Snippet Compiler to compile small bits of code Two different switcher tools, the ASP.NET Version Switcher and the Visual Studio .NET Project Converter Regulator To Build Regular Expressions .Net Reflector to Examine Assemblies ou can not expect to build a first-class application unless you use the best available tools. Besides well-known tools such as Visual Studio® .NET, there are a multitude of small, lesser-known tools available from the .NET community. In this article, I'm going to introduce you to some of the best free tools available today that target .NET development. I'll walk you through a quick tutorial of how to use each of them, some of which will save you a minute here and there, while others may completely change the way that you write code. Because I am squeezing so many different tools into this single article, I will not be able to cover each of them extensively, but you should learn enough about each to decide Which Tools Are Useful for your projects.snippet Compiler The Snippet Compiler is a small Windows®-based application that allows you to write, compile, and run code. This tool is useful if you have small pieces of code for which you do not want to create an entire Visual Studio .NET project (Along With all the files "come with it). As an example, let's say that I wanted to show you how to launch another application from the Microsoft® .NET Framework. In the Snippet Compiler I would start by creating a new file which creates a small console application. The snippet can be created inside The Main Method of the Console Application, Which is what i will do here. The follication code snippet Demonstrates How To create an instance of notepad from the .net framework: System.Diagnostics.Process Proc = New System.diagnostics.Process (); Proc.startinfo.filename = "notepad.exe"; proc.start (); Proc.waitForexit (); Of Course This Snippet 10.'s IS WHERE SNIPPET Compiler Comes Into Play .figure 1 Shows this Code Sample In Snippet Compiler. Figure 1 Snippet Compiler To test this snippet, just press the play button (green triangle), and it will run in debug mode. The snippet will generate a console application popup, and Notepad will appear. When you close Notepad, the console application will close as well. Personally, I have found Snippet Compiler to be invaluable when trying to create a small example for someone who has asked me for help, when normally I would have to create a project, make sure everything compiles, send them the code snippet, and then delete The project. Snippet Compiler Makes This Process Much Easier And Much More Pleasant. Snippet Compiler Was Written by Jeff Key and Can Be Downloaded from http://www.sliver.com/dotnet/snippetcompiler. Regulator Regulator is the most recent addition to my top tools list. It is a full-featured tool that makes it easy to build and test regular expressions. There is a renewed interest in regular expressions because of the excellent support for them in the .NET Framework . Regular expressions are used to define patterns in strings based on characters, frequency, and character order. They are most commonly used as a means to validate user input or as a way to find a string of characters inside a larger string-for instance, WHEN loops for a url e-mail address on a web page. Regulator allows you to enter a regular expression and some input against which you would be running this expression. This way you can see how the regular expression will act and what kind of matches it will return before implementing it in your application. Figure 2 shows Regulator with a simple regular expression.The document contains the regular expression, in this example it is [0-9] * which should match any number of digits in a row. The box in the bottom-right contains the input for this regular expression, and the box on the bottom-left shows the matches that this regular expression finds in the input. The ability to write and test regular expressions in a separate application like this is much easier than trying to work with them in your app . One of the best features in Regulator is the ability to search the online regular expressions library at regexlib.com. For example, if you enter the string "phone" in the search box, you will find more than 20 different regular expressions that will match Various Phone Numbers, Including Expressions for Uk, Australian, And Many Other Phone Numbers. Regulator Was Written by Roy Osherove and Can Be Downloaded AT http://royo.is-a-geek.com/regulator. Codesmith CodeSmith is a template-based code-generation tool that uses a syntax similar to ASP.NET to generate any type of code or text. Unlike many other code-generation tools, CodeSmith does not require you to subscribe to a particular application design or architecture Codesmith, You CAN Generate Anything From A Simple, Strongly Typed Collection To an entire Application. When you are building an application, you will often find yourself repeating certain tasks, whether it's writing data access code or building custom collections. CodeSmith is particularly useful at such times because you can write templates to automate those tasks and not only improve your productivity but Also Automate The Tasks That Are The Most Tedious To Perform. CodeSmith ships with a number of templates, including ones for all the .NET collection types as well as ones to generate stored procedures, but the real power of this tool comes from being able to create custom templates. To get you started, I'll PROVIDE A Quick Introduction To Building a Custom Template.Building A Custom Template CodeSmith templates are simply text files which you can create in any text editor. Their only requirement is that they be saved with the .cst file extension. The sample template that I'm going to build will accept a string and then build a class based ON That string. The first step to create the Template HEICH DECLARES The Language of The Template, The Target Language, And A Brief Description of the Template: <% @ CODETEMPLATE LANGUAGE = "C #" TargetLanguage = "C #" Description = "car template"%> <% @ CODETEMPLATE LANGUAGE = "C #" TargetLanguage = "C #" Description = "car template"%> The next part of the template is the property declarations, where you declare the properties that will be specified each time the template is run. With this template, the single property that I'm going to use is just a string, so the property declaration Looks like this: <% @Property name = "classname" type = "string" category = "context" Description = "Class Name"%> This property declaration will make the ClassName property appear in the CodeSmith property window so that it can be specified when the template is run. The next step is to actually build the body of the template, which is very similar to coding with ASP.NET. You can see the body of the template infigure 3. [Editor's update - 6/16/2004: The Code in Figure 3 HAS been updated to be defe for multithread operations. As you can see, the template will take the string input and generate a singleton class using that class name. In the template body, the same opening and closing tags are used as in ASP.NET. In this template, I am simply inserting the Property Value, But You Can Also Use any type of .net code inside tags. Once the Template IS Complete, You Load It Into Codesmith by Either Double-Click Supportation. Figure 4 shows this template loaded Into Codesmith. You can see That The Property on The Left Is The One I Declared In The Template. If I Enter "Singletonclass" As The Class Name and Click The Generate Button, The Class Shown In The Bottom Part of Figure 3 Will be generated. CodeSmith is relatively easy to use and can produce some incredible results if applied correctly. One of the most common sections of an application that is targeted for code generation is the data access layer. CodeSmith includes a special assembly called the SchemaExplorer which can be used to Generate Templates from tables, Stored Procedures, or Almost Any Other SQL ServerTM Object. Codesmith Was Written by Eric J. Smith and is Available For Download At http://www.ericjsmith.net/codesmith. NUnit NUnit is an open source unit testing framework built for the .NET Framework. NUnit allows you to write tests in the language of your choice to test a specific function of your application. Unit tests are an excellent way to test the functionality of your code when you first write it, and also to provide a method for regression testing of your application. The NUnit application provides a framework for writing unit tests, as well as a graphical interface to run these tests and view the results.Writing an NUnit Test As an example, I'm going to test the functionality of the Hashtable class in the .NET Framework to determine if two objects can be added and then retrieved. My first step will be to add a reference to the NUnit.Framework assembly, which .. will give me access to the attributes and methods of the NUnit framework Next I'll create a class and mark it with the TestFixture attribute This attribute lets NUnit know that this class contains NUnit tests: Using system; Using system.collections; Using nunit.framework; Namespace NUNITEXAMPLE { [TestFixTure] Public class hashtabletest { Public hashtabletest () { } } } NEXT I'll Create a Method and Mark It With The NUNIT KNOWS THAT I'LL IS A TEST. THEN I'll Set Up A Hashtable and Add Two Values To It, Then Use The assert.ArequalMethod To See et estread That I added to the hashtable: [TEST] Public void hashtableaddtest () { Hashtable ht = new hashtable (); Ht.Add ("Key1", "Value1"); HT.Add ("Key2", "Value2"); Assert.Arequal ("Value1", HT ["Key1"], "Wrong Object Returned!"); Assert.Arequal ("Value2", HT ["Key2"], "Wrong Object Returned!"); This will confirm that I can add and then retrieve values from the Hashtable-a simple test, but one that showcases the capabilities of NUnit. There are a number of test types, as well as various Assert methods, that can be used to test every Part of your code. To Run Test, I'll Need To Build The Project, Open The generated assembly in the NUNIT Application, and The Click The Run Button. Figure 5 shows the results. I get a warm and fuzzy feeling when I see that big green bar because it lets me know that the test passed. This simple example shows how easy and powerful NUnit and unit testing can be. Being able to write a Unit Test That Can Be Saved and Run WHENEVER You Change Not Only Makes It Easier for You To Detect Defects in your code, But The result is this you can deliver better application. Figure 5 NUnit NUNIT IS An Open-Source Project That Is Available For Download from Http://www.nunit.org. There Is Also An Excellent NUNIT VISUAL Studio .Net Add-in Which Allows You To Run Unit Tests Directly from Visual Studio. This Can Be Found At Http://sourceforge.net/projects/nunitaddin. for more information on nunit and its place in test-driven development, see the articles Test-Driven C #: Improve The Design and Flexibility of Your Project with Extreme Programming Techniques "in The April 2004 Issue Of MSDN® Magazine. FXCOP The .NET Framework is very powerful, which means there is great potential to create excellent applications, but there is equal opportunity to create poor programs. FxCop is one of the tools that can be used to help create better applications by enabling you to examine an assembly and check it for compliance using a number of different rules. FxCop comes with a set number of rules created by Microsoft, but you can also create and include your own rules. for instance, if you decided that all classes should have a default constructor that takes no arguments, you could write a rule that checks for a constructor on each class of an assembly. This way, no matter who writes the code, you will have a certain level of consistency. If you want more information on creating custom rules See John Robbins'bugslayer Column on The Subject in The June 2004 Issue of Msdn Magazine. So let's take a look at FxCop in action and see what it finds wrong with the NUnitExample assembly that I have been working with. When you open FxCop you first need to create an FxCop project and then add to it the assembly that you want to test Over The Project, You CAN Press Analyze, And FxCop Will Examine The assembly. The Errors and Warning Found in this Assembly Are Shown in Figure 6. FxCop found a couple of problems with my assembly. You can double-click on an error to see the details, including a description of the rule and where you can find more information. (Something you can do for fun is run FxCop on the Framework Assemblies and see what Turns Up.) FxCop can help you create better, more consistent code, but it can not make up for poor application design or just plain poor programming. FxCop is also not a replacement for peer code review, but because it can catch a lot of errors before code review, More Time Can Be Spent On Serious Issues Rather Than Haiving To Worry About Naming Conventions.Fxcop Was Developed by Microsoft and IS Available For Download from http://www.gotdotnet.com/team/fxcop. Lutz Roeder's .Net Reflector The next essential tool is called .NET Reflector, which is a class browser and decompiler that can examine an assembly and show you just about all of its secrets. The .NET Framework introduced the world to the concept of reflection which can be used to examine any .NET-based code, whether it is a single class or an entire assembly. Reflection can also be used to retrieve information about the various classes, methods, and properties included in a particular assembly. Using .NET Reflector, you can browse the classes and methods of an assembly, you can examine the Microsoft intermediate language (MSIL) generated by these classes and methods, and you can decompile the classes and methods and see the equivalent in C # or Visual Basic® .NET. To Demonstrate The Workings of .Net Reflector, I am Going to Load and Examine The NUNITEXAMPLE Assembly Already shown. Figure 7 shows this assembly loaded in .net Reflector. Figure 7 NUNITEXAMPLE Assembly Inside of .NET Reflector the Makes Up A Method, Click ON The Method and Select Disassembler from The Menu. In addition to being able to view the MSIL, you can also view the method as C # by selecting Decompiler under the Tools menu. You could also view this method decompiled to Visual Basic .NET or Delphi by changing your selection under the Languages menu. Here Is The code That .Net Reflector Generated: Public Void HashTableAddTest () { Hashtable hashtable1; Hashtable1 = new hashtable (); Hashtable1.add ("key1", "value1"); Hashtable1.add ("key2", "value2"); Assert.Arequal ("Value1", Hashtable1 ["Key1"], "WRONG OBJECT RETURNED!"); Assert.Arequal ("Value2", Hashtable1 ["Key2"], "WRONG OBJECT RETURNED!"); } The Previous Code Looks Very Much Like The Code I Actually Wrote for this method. Here is the actual code from this assembly: Public void hashtableaddtest () { Hashtable ht = new hashtable (); Ht.Add ("Key1", "Value1"); HT.Add ("Key2", "Value2"); AskERT.Areequal ("Value1", HT ["Key1"], "WRONG OBJECT RETURNED!"); AskERT.Areequal ("Value2", HT ["Key2"], "WRONG OBJECT RETURNED!"); } Although There is the code, They is Functionally Identical. While this example was a good way to show actual code versus decompiled code, it does not represent what I consider to be the best use of .NET Reflector, which is to examine .NET Framework assemblies and methods. The .NET Framework offers many different ways to perform similar operations. For example, if you need to read a set of data from XML, there are a variety of different ways to do this using XmlDocument, XPathNavigator, or XmlReader. By using .NET Reflector, you can see what Microsoft used when writing the ReadXml method of the DataSet, or what they did when reading data from the configuration files. .NET Reflector is also an excellent way to see the best practices for creating objects like HttpHandlers or configuration handlers because you get to see how the Team at Microsoft Actually Built Those Objects in The Framework..NET Reflectte Was Written by Lutz Roeder and Can Be Downloaded from http://www.aisto.com/roeder/dotnet. NDOC Code documentation is almost always a dreaded task I am not talking about the early design documents, or even the more detailed design documents;. I am talking about documenting individual methods and properties on classes The NDoc tool will automatically generate documentation for your code using. reflection to examine the assembly and using the XML generated from your C # XML comments. XML comments are only available for C #, but there is a Visual Studio .NET Power Toy called VBCommenter which will do something similar for Visual Basic .NET. In addition, The Next Release of Visual Studio Will Support XML Comments for more languages. With NDoc you are technically still documenting your code, but you are documenting as you write it (in the XML comments), which is much easier to swallow. The first step when using NDoc is to turn on XML comments generation for your assembly. Right -click the project and select Properties | Configuration Properties |. Build, then enter a path in which to save the XML file in the XML Documentation File option When the project is built, an XML file will be created with all of the XML comments included . Here is a look at a maethod from the NUNIT EXAMPLE DOCUMENTED with XML: /// /// THIS TEST ADDS A Number of Values To The Hashtable Collection /// and the retrieves those value and checks if the match. /// summary> [TEST] Public void hashtableaddtest () { //Method Body Here } THE XML Documentation On this Method Will Be extracted and saved in the xml file, shown here: AND THEN RETRIEVES Those Values and Checks if the match. summary> member> NDoc uses reflection to look at your assembly, then reads the XML in this document, and matches them up. NDoc uses this data to create any number of different documentation formats, including HTML help files (CHMs). After generating the XML file, the NEXT Step is to loading the assembly and the xml file into ndoc So The can be processed. this is done simply by opening ndoc and clicking the add button. Once the assembly and XML file are loaded into NDoc and after you customize the output using the range of properties available, clicking on the Generate button will start the process of generating the documentation. Using the default properties, NDoc generates some very attractive and functional. Html and .chm Files, Thereby Automating In A Quick and Effect Manner What Would OtherWise Be a TEDious Task.ndoc is An Open Source Project and Can Be Downloaded from Http://ndoc.sourceforge.net. Nant NAnt is a .NET-based build tool that, unlike the current version of Visual Studio .NET, makes it easy to create a build process for your project. When you have a large number of developers working on a single project, you can ' t rely on the build from a single user's box. you also do not want have to build the project manually on a regular basis. Instead, you create an automated build process that runs every night to. NAnt allows you to build your solution, copy files, run NUnit tests, send e-mail, and much more. Unfortunately, NAnt is lacking a nice looking graphical interface, but it does have a console application and XML files that specify which tasks should be completed during the build process. Note that . Nant in action In this example I am going to create an NAnt build file for the NUnitExample solution that I created earlier. First I need to create an XML file with the .build extension, place it in the root of my project, and then add an XML declaration To the top of the file. The first tag I need to add to the file is the project tag: XML Version = "1.0"?> target> Inside the target element, I am going to set the name of the target to build and create a description of what this target will do. I'll also create a csc element, which is used to specify what should be passed to the csc C # COMPILER. Let's take a look at the csc element: references> Sources> csc> First, I have to set the target of the csc element. In this case. 4., I set the target to library. Next, i have to set the output of the csc element, which is where there. dll file will be created. Finally, I need to set the debug property, which determines whether the project will be compiled in debug. Since I created a property earlier to store this value, I can use the following string to access the value of that property:. $ {debug} The csc element also contains a number of sub-elements I need to create two elements:. the references element will tell NAnt which assemblies I need to reference for this project, and the sources element will tell NAnt which Files to include, I reference. I reference.dll assmblying and incrure the hashtabletest.cs file. The completion file. The Complete Build File Is Shown in Figure 8. (You Would Normal Also Create a Clean Target this) To build this file I need to go to the root directory of my project, where the build file is located, and execute nant.exe from that location. If the build is successful, you can find the .dll and .pdb file in the bin directory of this application. While using NAnt is definitely not as easy as clicking Build in Visual Studio, it is a very powerful tool for developing a build process that runs on an automated schedule. NAnt also includes helpful features such as the ability to run Unit Tests or Copy Additional Files (Features That Are Not Supported by The Current Visual Studio Build Process) .nant Is An Open Source Project and Can Be Downloaded from Http://nant.sourceforge.net. Switch Tools I have lumped together two separate tools under the heading Switch Tools. These two tools are rather simple, but can be extremely useful. The first is the ASP.NET Version Switcher, which can be used to switch the version of ASP.NET that a Virtual Directory Is Running Under. The Second Tool Is The Visual Studio Converter, Which Can Be Used to Switch A Project File From Visual Studio .NET 2002 TO Visual Studio .NET 2003. When IIS handles a request, it looks at the extension of the file that is being requested, and then based on the extension mappings for that Web site or virtual directory, it either delegates the request to an ISAPI extension or handles it itself. This is how ASP.NET works; extension mappings are registered for all of the ASP.NET extensions and directs them to the aspnet_isapi.dll This works flawlessly until you install ASP.NET 1.1, which upgrades the extension mapping to the new version of aspnet_isapi.. dll. This causes errors when an application built on ASP.NET 1.0 tries to run with version 1.1. to fix this, you can switch all of the extension mappings back to the 1.0 version of aspnet_isapi.dll, but with 18 extension mappings it is not a lot of fun to do this by hand. This is where the ASP.NET Version Switcher becomes useful. This small utility can be used to switch the version of the .NET Framework that any single ASP.NET application is using.Figure 9 ASP.NET VERSION SWITCHER Figure 9 shows the ASP.NET Version Switcher in action. Using it is as simple as selecting the application and then selecting the version of the .NET Framework that you would like the application to use. The tool then uses the aspnet_regiis.exe command- Line Tool To Switch The Application To The SELECTED VERSION OF THE Framework. This Tool Will Become Even More Useful As Future Versions of Asp.Net and The .NET Framework is Released. ASP.NET VERSION SWITCHER WAS WRITTEN BY DENIS BAUER AND IS AVAILABLE for Download from Http://www.denisbauer.com/nettools/aspnetversionswitcher.aspx. The Visual Studio .Net Project Converter (See Figure 10) is very similar to the ASP.NET Version Switcher, except that it is used to switch the version of a Visual Studio project file. Even though there is only a small difference between versions 1.0 and 1.1 of the .NET Framework, once a project file from Visual Studio .NET 2002 is converted to Visual Studio .NET 2003, it can not be converted back. While this might not be an issue most of the time (since there are few breaking changes between the .NET Framework versions 1.0 and 1.1), at some point you may need to switch a project back. This converter can convert any solution or project file from Visual Studio 7.1 (Visual Studio .NET 2003) to Visual Studio 7.0 (Visual Studio .NET 2002), and back if Necessary.figure 10 Visual Studio .NET Project Converter The Visual Studio .Net Project Converter Was Written By Dacris Software. It is Available for Download from From http://www.codeproject.com/macro/vsconvert.asp. Conclusion This has been a bit of a whirlwind tour of these tools, but I have tried to present you with at least enough information to whet your appetite. I trust that this article has provided you with some insight into a couple of free tools that you can start using right away to write better projects. I also urge you to make sure you have all the other right tools available to you, whether it is newest version of Visual Studio, a powerful computer, or a free utility. Having the right tools can Make all the difference. James Avery is a consultant working with .NET and other Microsoft technologies. He has written a number of books and articles, his most recent book being ASP.NET Setup and Configuration Pocket Reference (Microsoft Press, 2003). You can e-mail him At javery@infozerk.com and read his weblog at http://www.dotavery.com/blog.from The July 2004 Issue of Msdn Magazine.get It at Your Local NewsStand, or Better Yet, Subscribe.