: Http://nant.sourceforge.net/
1. Create a simple target:
Use <target> </Target> as the marker to output the predefined constants project_name and project_ver.
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <project name = "mybuild" default = "testecho" basedir = ". "xmlns =" http://nant.sf.net/schemas/nant.xsd "> <br/> <property name =" project_name "value =" webtestproject "/> <br/> <property name =" project_ver "value =" 2011.001.001 "/> </P> <p> <target name =" testecho "Description =" for test using "> <br/> <echo message =" the current project name is $ {project_name} "/> <br/> <echo message =" the current project version is $ {project_ver} "/> <br/> </Target> <br/> </Project>
Save the preceding XML snippets as C:/Default. Build, download Nant, set the Nant execution directory to the system directory, and run the following command:
Nant-buildfile: "C:/Default. Build" testecho or Nant-buildfile: "C:/Default. Build", the following result is displayed:
Or download a software called editor4nant for editing and debugging.
2. Reference an external file:
You can create an external file named after build, define several constants, and reference them in the main file.
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <project name = "external"> <br/> <property name = "ext_name" value = "external value in file external. build. "/> <br/> </Project>
Save the preceding XML snippets as C:/external. Build, and add the following to default. Build:
<Include buildfile = "External. Build"/>
To reference the external file. Add the following statement to the target tag for testing:
<Echo message = "external info :$ {ext_name}"/>
Run Nant-buildfile: "C:/Default. Build" testecho to view the new output.
3. Set the external file name to the variable name for dynamic reference:
In the default. Build File
<Include buildfile = "External. Build"/>
Changed:
<Include buildfile = "$ {config_file}"/>
Run Nant-buildfile: "C:/Default. Build"-D: constm_file = "External. Build" testecho. The preceding output is also displayed.
4. Insert C # code in the default. Build file:
Nant supports inserting C # code in the build file. The default namespace is system and system. io, system. text, system. collections, the code is marked by <SCRIPT> </SCRIPT>. Add the following fragments to default. Build:
<Script language = "C #" prefix = "util"> <br/> <code> <! [CDATA [<br/> [function ("get-Hello-World")] <br/> Public static string gethelloworld () <br/> {<br/> return "Hello world. "; <br/>}< br/>]> </code> </P> <p> </SCRIPT>
And add the echo statement for testing:
<Echo message = "Message from code is :$ {util: Get-Hello-World ()}"/>
5. Call external programs:
Add the following fragments to default. Build:
<Target name = "runnotepad"> <br/> <exec program = "notepad.exe"> <br/> <Arg line = "C: /new.txt "/> <br/> </exec> <br/> </Target>
Run Nant-buildfile: "C:/Default. Build" runnotepad
The prompt box for creating new.txt is displayed.
6. Attributes of depends:
If a build file has multiple targets and dependencies between them, you can use the depends attribute for maintenance. For example:
<Target name = "A"> <br/> <target name = "B" depends = "A"/> <br/> <target name = "C" depends =" b, A "/> </P> <p> <target name =" D "/> <br/> <target name =" E "/> <br/> <target name = "F" depends = "D, e, a "/>
The execution sequence of target B is a-> B, and the execution sequence of target C is a-> B-> C. The execution sequence of target F is: d-> E->.
7. Conditional test:
Nant also supports conditional testing. It uses built-in or custom functions to make some judgments. when the conditions are met, the corresponding tasks are executed.
Add the following fragments to default. Build:
<Target name = "testcondition"> <br/> <if test = "$ {string: INS ins (project_ver, '001 ')} "> <br/> <echo message =" current project version is 001, we need to do something... "/> <br/> <call target =" runnotepad "/> <br/> </If> <br/> </Target>
Run Nant-buildfile: "C:/Default. Build" testcondition
If the predefined constant project_ver contains a 001 string, the task runnotepad will be executed. Otherwise, nothing will be done.
For more information about Nant applications, see: http://nant.sourceforge.net/release/latest/help/index.html