Ten must-have .NET development gadgets (8): Nant

zhaozj2021-02-16  53

Ten must-have .NET development gadgets (8): Nant

Author: James Avery translation: lucentoff

Source: http://msdn.microsoft.com/msdnmag/issues/04/07/musthavetools/default.aspx declaration: The copyright belongs to the original author, reproduced please indicate the source!

Nant

Nant is unlike the current version of Visual Studio .NET, it is a .NET-based compilation tool that enables the project's compilation process very easy. When the project developer is a lot, it is impossible to rely on someone to perform the compilation process. You don't want to manually compile the project, but in turn to create a compilation process that is automatically run every night. Nant allows you to perform compilation solutions, copy files, run NUnit test, send E-mail, etc. Unfortunately, NANT has no beautiful graphical interface, but it includes a console application and XML file, the XML file specifies the task that should be completed during the compilation process. Note that the Visual Studio 2005 new compilation platform Msbuild provides a very robust compilation function and is also driven by XML-based project files.

Nant

In this example, I will create a NANT compilation file for the NUNITEXAMPLE solution created in front. First create an XML file with .build as an extension, place it in the root of the project, then add an XML declaration at the top of the file. The first added tag is a project standard:

The NUNIT EXAMPLE PROJECT

The project marking sets the project name, the default target and the base directory. Description Tags Set a brief description of the item.

The next is to add an attribute tag to store the settings that can be accessed from the file. In this example, I want to create an attribute called debug, which can be set to true or false, which is used to determine if the project is compiled (this special property does not actually affect the compilation of the project, it is you A simple variable set can be read after actually deciding how to compile the project.) The property tag is as follows:

Then, create a target tag. A project can contain multiple tags, which are specified at NANT runtime. If you do not specify a target, use the default setting value in the project element. In this example, the default goal is "build". Let us look at the target element, which contains most of the compilation information:

In the target element, I set up the target name to be compiled and create a task description. Let's also create a CSC element that specifies the content that should be passed to the C # compiler CSC. Let's take a look at the CSC element:

Debug = "$ {debug}">

First, you must set the goal of the CSC element. In this case I will create a .dll file, so I set the target to "library". Next, set the output of the CSC element, which specifies the creation of the.dll file. Finally, you need to set the debug property, which determines whether the project is compiled when debugging. Since a property has created a property to store this value, you can use the following string to access the value of this property: $ {debug}. The CSC element also contains some child elements, here you need to create two elements: Reference elements Inform NANT to need the assembly referenced for this project, the source file element tells Nant's compiled files. In this example, I will quote the NUNIT.FRAMEWORK.DLL assembly and include the HashTableTest.cs file. The final compilation file is shown in Figure 8. (Under normal circumstances, you should also create a Clean target for deleting the generated file, but I will omitrate for the article short.) Figure 8 Nant Compilation File To compile this file, you need to be in the project root of the project where the .build file is located. Execute nant.exe. If the compile is successful, you can find a .dll and .pdb files in the bin directory of the application. Although it is not as easy as Nant's Click "Build" in Visual Studio, it is a very powerful tool for the development of the development, which is automatically run. NANT also includes useful features, such as running unit testing or copying other files (current Visual Studio compilation processes do not support these features).

Nant is an open source project, download URL: http://nant.sourceforge.net/.

Related resources: with sound access new year fireworks animation effects - html-code

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

New Post(0)