Ten essential tools that each .NET developers should download

xiaoxiao2021-03-06  164

? 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 for generating regular expressions •. Net Reflector for analyzing assembly 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. Snippet Compiler Snippet Compiler is a Windows®-based minic 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 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. Figure 2 The document contains the regular expression - in this example, it is [0-9] *, which should match any 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. Generating 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 brief template for template: <% @ 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. As far as this template is, the only property I want to use is just a string, so the attribute declaration 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. The following is the main body of this template: Custom TemplatePublic Sealed Class <% = ClassName%>

{

Private static volatile <% = classname%> _INSTANCE;

Private <% = classname%> () {}

Private static readonly object _syncroot = new object ();

Public static <% = ClassName%> Value

{

get

{

IF (_Instance == null)

{

Lock (_syncroot)

{

IF (_Instance == null)

{

_INSTANCE = New <% = ClassName%> ();

}

}

}

Return_INSTANCE;

}

}

}

Singletonclasspublic Sealed Class Singletonclass

{

Private static volatile singletonclass _instance;

Private singletonclass () {}

Private static readonly object _syncroot = new object ();

Public Static Singletonclass Value

{

get

{

IF (_Instance == null)

{

Lock (_syncroot)

{

IF (_Instance == null)

{

_INSTANCE = New Singletonclass ();

}

}

}

Return_INSTANCE;

}

}

}

? 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. Figure 4 You can see the properties on the left is the properties I declared in this template. If I enter "Singletonclass" as class name, and click the Generate button, the class displayed at the bottom of the template code is 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 test: use system; use 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). The FXCOP .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. Figure 6 FXCOP found several issues 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 does not 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 Next is an essential tool called .Net Reflector, it is a class browser and an anti-compiler that analyzes the assembly and showing you all the secrets. 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 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.

///

[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:

THIS TEST ADDS A Number of Values ​​To The Hashtable Collection

And the Retrieves Those Values ​​and Checks if the match.

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. In this example, I will create a Nunit 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: The NUnit Example Project

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:

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:

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 displayed in the following code. (You usually have to create a clean target, used to delete the generated file, but I have omitted it for the sake of simplicity.) The NUNIT EXAMPLE PROJECT

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. The 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. • Small junction This article introduces the above tools in the way, but I have tried to at least 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.

转载请注明原文地址:https://www.9cbs.com/read-128343.html

New Post(0)