By - scmGalaxy.com
The configuration files are XML-based, calling out a target tree where various tasks get executed. Each task is run by an object that implements a particular Task interface.
Latest Release - 0.92
@echo off
"C:\Program Files\NAnt\bin\NAnt.exe" %*
<?xml version="1.0" encoding="utf-8" ?>
<project name="HelloWorld">
<echo message="Hello, World!" />
</project>
<?xml version="1.0" encoding="utf-8" ?>
<project name="HelloWorld" default="message" basedir="." >
<target name="message">
<echo message="Hello, World!" />
</target>
</project>
<?xml version="1.0" encoding="utf-8" ?>
<project name="HelloWorld" default="go">
<property name="message" value="Hello World!"/>
<target name="go">
<echo message="${message}"/>
</target>
</project>
Attribute | Description | Required |
---|---|---|
name | The name of the project. | No |
default | The default target to execute when no target is supplied on the command-line. | No |
basedir | The base directory from which all path calculations are done. If not set, the parent directory of the buildfile will be used. | No |
a description for the project can be provided as a top-level <description> element
<?xml version="1.0" encoding="utf-8" ?>
<project name="HelloWorld">
<description>This is a description.</description>
<echo message="Hello, World!" />
</project>
Attribute | Description | Required |
---|---|---|
name | The name of the project. | Yes |
depends | A comma-separated list of names of targets on which this target depends. | No |
if | An expression that should evaluate to true in order for this target to execute. | No |
unless | An expression that, when evaluated to true, will cause the target to be skipped. | No |
description | A short description of this target's function. | No |
A task is a piece of code that can be executed.
Tasks have a common structure:
<name attribute1="value1" attribute2="value2" ... />
List of all Tasks - http://nant.sourceforge.net/release/0.85/help/tasks/index.html
<project name="Hello World" default="build" basedir="." xmlns="http://nant.sf.net/release/0.86-beta1/nant.xsd">
<description>The Hello World of build files.</description>
<property name="debug" value="true" overwrite="false" />
<target name="clean" description="remove all generated files">
<delete file="HelloWorld.exe" failonerror="false" />
<delete file="HelloWorld.pdb" failonerror="false" />
</target>
<target name="build" description="compiles the source code">
<csc target="exe" output="HelloWorld.exe" debug="${debug}">
<sources>
<includes name="HelloCS.cs" />
</sources>
</csc>
</target>
</project>
// Allow easy reference to the System namespace classes.
using System;
// This class exists only to house the entry point.
class MainApp {
// The static method, Main, is the application's entry point.
public static void Main() {
// Write text to the console.
Console.WriteLine("Hello World using C#!");
}
}
csc.exe /debug+ /out:.\HelloCS.exe helloCS.cs
Properties that should be accessible to all build files on a system can be defined in the <properties> node of the NAnt configuration file (NAnt.exe.config).
More - http://nant.sourceforge.net/release/0.85/help/fundamentals/properties.html
NAnt tries to execute the targets in the depends attribute in the order they appear from left to right.
It is possible that a target can get executed earlier when an earlier target depends on it:
<target name="A"/>
<target name="B" depends="A" />
<target name="C" depends="B" />
<target name="D" depends="C,B,A" />
Suppose we want to execute target D. From its depends attribute, you might think that first target C, then B and then A is executed. Wrong! C depends on B, and B depends on A, so first A is executed, then B, then C, and finally D.
<?xml version="1.0" encoding="utf-8" ?>
<project name="HelloWorld" default="go">
<property name="message" value="Hello World!"/>
<property name="module-A-present" value="True"/>
<target name="go" if="${module-A-present}">
<echo message="${message}"/>
</target>
</project>
<exec program="ping">
<arg value="google.com" />
</exec>
<exec program="CMD.EXE" commandline="/C DatabaseInstallation.cmd" workingdir="${installPath}">
<arg value="${Database_ServerInstanceName}" />
<arg value="${Database_Name}"/>
<arg value="${Database_Domain}"/>
<arg value="${Database_DtsPackagesFolder}"/>
</exec>
To override properties specified in the build file use the -D:property=value option, where property is the name of the property, and value is the value for that property.
<solution configuration="release" solutionfile="test.sln" />
<solution configuration="release">
<projects>
<includesfile name="projects.txt" />
</projects>
</solution>
More - http://nant.sourceforge.net/release/0.85-rc1/help/tasks/solution.html
Loggers extend the capabilities of listeners and add the following features:
- Receives a handle to the standard output and error print streams and therefore can log information to the console or the -logfile specified file.
- Logging level (-quiet, -verbose, -debug) aware.<project name="MailLogger Test" default="build">
<property name="MailLogger.mailhost" value="smtp.wherever.be" />
<property name="MailLogger.from" value="me@telenet.be" />
<property name="MailLogger.failure.notify" value="true" />
<property name="MailLogger.success.notify" value="true" />
<property name="MailLogger.failure.to" value="support@home.be" />
<property name="MailLogger.success.to" value="support@home.be" />
<property name="MailLogger.failure.subject" value="Nightly build failure !" />
<property name="MailLogger.success.subject" value="Nightly build successful" />
<property name="MailLogger.failure.attachments" value="MailLogger.failure.files" />
<property name="MailLogger.success.attachments" value="MailLogger.success.files" />
<!-- set of files to attach when build fails -->
<fileset id="MailLogger.failure.files">
<include name="dump.log" />
<include name="trace.txt" />
</fileset>
<!-- set of files to attach when build is successful -->
<fileset id="MailLogger.success.files">
<include name="trace.txt" />
</fileset>
<target name="build">
<echo message="Starting build" />
<echo message="Finished build" />
</target>
</project>
<?xml version="1.0"?>
<project name="testNUnit">
<nunit2>
<formatter type="Xml" usefile="true" extension=".xml" outputdir="C:\NAnt\NUnitResults\" />
<test assemblyname="E:\testing\TestClassLibrary1\\bin\Debug\TestClassLibrary1.dll" />
</nunit2>
</project>
<?xml version="1.0"?>
<project name="TestNDoc">
<ndoc>
<assemblies basedir="E:\testing\ClassLibrary1\ClassLibrary1\bin\Debug\">
<include name="ClassLibrary1.dll" />
</assemblies>
<summaries>
<include name="ClassLibrary1.xml" />
</summaries>
<documenters>
<documenter name="MSDN">
<property name="OutputDirectory" value="C:\MyDocs\NDOC" />
<property name="HtmlHelpName" value="MyProject" />
<property name="ShowMissingSummaries" value="True" />
<property name="HtmlHelpCompilerFilename" value="hhc.exe" />
<property name="IncludeFavorites" value="False" />
<property name="Title" value="MySystem (NDoc)" />
<property name="SplitTOCs" value="False" />
<property name="DefaulTOC" value="" />
<property name="ShowVisualBasic" value="False" />
<property name="ShowMissingSummaries" value="True" />
<property name="ShowMissingRemarks" value="False" />
<property name="ShowMissingParams" value="True" />
<property name="ShowMissingReturns" value="True" />
<property name="ShowMissingValues" value="True" />
<property name="DocumentInternals" value="True" />
<property name="DocumentProtected" value="True" />
<property name="DocumentPrivates" value="False" />
<property name="DocumentEmptyNamespaces" value="False" />
<property name="IncludeAssemblyVersion" value="True" />
<property name="CopyrightText" value="Etomic 2005" />
<property name="CopyrightHref" value="" />
</documenter>
</documenters>
</ndoc>
</project>
<project name="testNCover" default="coverage" failonerror="true">
<loadtasks assembly="NCoverExplorer.NAntTasks.dll" />
<target name="coverage" description="Code coverage test run.">
<ncover
program="C:\Program Files\NCover\Ncover.console.exe"
commandLineExe="C:\Program Files\NUnit-Net-2.0 2.2.8\bin\nunit-console.exe"
commandLineArgs="E:\REL\Test\TestTest\bin\Debug\TestTest.dll"
logLevel="Verbose"
excludeAttributes="CoverageExcludeAttribute">
<assemblies basedir="E:\REL\Test\Test\bin\Debug">
<!-- include this to have only the test.dll reviewed and not the TestTest.dll -->
<include name="Test.dll"/>
</assemblies>
</ncover>
http://www.codeproject.com/Articles/38718/Building-and-Deploying-Using-NAnt
http://www.4guysfromrolla.com/articles/120104-1.aspx
http://www.codeproject.com/Articles/19964/Introduction-to-NAnt
http://nant.sourceforge.net/release/0.85/help/tasks/index.html