NAnt Tutorial

From DojoWiki

Jump to: navigation, search

Installing NAnt

Download the most recent NAnt from http://nant.sourceforge.net

The most recent release, as of 1/20/2007, is 0.85. I chose to download a Binary release in .zip format. Source releases and tar format are available as well.

NAnt doesn't include an installer, so you'll need to extract the files manually. Place them in any directly (eg., c:\nant-0.85\)

Image:NantExtractDir.png

Then add the \bin directory to your path.

Image:SetPath.png

Using NAnt

First you'll need to create a basic build file.

<project name="test" default="basic">
  <target name="basic" >
    <echo>This is a basic build</echo>
  </target> 
</project>

But here is a more complicated build

<project name="SeleniumDotNet" default="test" basedir=".">
<property name="dir.output" value=".\bin"/>

  <target name="clean" >
    <delete dir="${dir.output}" failonerror="false" />
    <mkdir dir="${dir.output}" />
    <copy file="C:\selenium-remote-control-0.9.0\dotnet\ThoughtWorks.Selenium.Core.dll" todir="${dir.output}" />
  </target>

  <target name="compile" depends="clean" >
    <echo>Starting the build</echo>
    <csc target="exe" output="${dir.output}\SeleniumDotNetTest.exe" debug="true">
      <sources>
        <include name="**/*.cs" />
      </sources>
      <references>
        <include name="C:\NUnit-2.2.7\bin\nunit.framework.dll" />
        <include name="C:\selenium-remote-control-0.9.0\dotnet\ThoughtWorks.Selenium.Core.dll" />
      </references>
    </csc>
  </target>
  <target name="test" depends="compile" >
    <nunit2>
      <formatter type="Plain" />
      <test assemblyname="${dir.output}\SeleniumDotNetTest.exe" >
	<assemblies>
	  <include name="C:\NUnit-2.2.7\bin\nunit.framework.dll" />
          <include name="C:\selenium-remote-control-0.9.0\dotnet\ThoughtWorks.Selenium.Core.dll" />
	</assemblies>
      </test>
    </nunit2>
  </target>

</project>

If there is only one *.build file in the directory from which NAnt is being executed, that one will get called using the "default" target

Image:build.png

Personal tools