Skip to content
derickbailey edited this page Aug 12, 2010 · 5 revisions

To simplify the calling of a nant.exe, the NAntTask can be used in a rakefile. Be sure to require ‘albacore’ at the top of your rakefile, after installing the Albacore gem.

How to use the NAntTask

Here is an example of how to use the NAntTask


desc "Run a sample build using the NAntTask"
nant :full_build do |nant|
  nant.path_to_command = "bin/tools/nant/nant.exe"
  nant.build_file = "src/TestSolution/TestSolution.build"
  nant.properties :debug => true, "build.mode" => :fast
  nant.targets :Clean, :Build, :Specs

end

Initializer Parameter: task name (required)

You must specify any name you wish to identify this rake task.

path_to_command (required)

You must specify the location of the nant.exe that you wish to use.

If an invalid or incorrect nant path is specified (i.e. if the file or folder specified does not exist), the NAntTask will fail with an exception stating that the nant file was not found:

F, [2009-10-04T14:01:33.481000 #5436] FATAL -- : Command not found: i don't exist.exe
F, [2009-10-04T14:01:33.481000 #5436] FATAL -- : Nant task Failed. See Build Log For Detail
rake aborted!

build_file (optional)

This is the nant build file that specifies the target(s) you want to run. If you don’t provide a valid nant build file, nant will try to use the first *.build file it finds in the current directory.

If no build file can be found, the NAntTask will fail with an error stating that a build file could not be found.

properties (optional)

You can specify any valid NAnt command line property as a hash literal. For example, if you wanted to provide a property called “foo” with a value of “bar”, and a property called “widget” with a value of “wombat”, you would do so like this:

msb.properties :foo => :bar, :widget => :wombat

You are not required to use :symbols for these values. You can provide string values if you wish.

The properties setting is optional. If you don’t provide any values for this, the defaults from your NAnt build file will be used.

targets (optional)

You can specify any valid target for your NAnt build file as an array. The example above is calling the Clean, Build and then Specs targets, in that order. If you only want to call Rebuild, as another example, you would set the targets like this:

nant.targets :Rebuild

You are not required to use :symbols for these values. You can provide string values if you wish. However, if you try to use data types such as “true” or “false”, you must specify them as symbols or strings, directly.

The properties setting is optional. If you don’t provide any values for this, the defaults from your NAnt build file will be used.

Logging

The NAntTask uses the built in logging options to provide some potentially useful information at run-time. By default, no additional information is logged, other than what NAnt produces.

verbose mode

When the log_level is set to :verbose, the full command line call for NAnt will be logged. This includes the expanded path to the nant exe as well as the command line parameters that are passed to it.

D, [2009-09-28T09:18:22.254000 #7152] DEBUG -- : Executing NAnt: "bin/tools/nant/nant.exe" "src/TestSolution/TestSolution.build" -D:debug=true -D:build.mode:fast Clean Build

YAML configuration

This task supports configuration via an external YAML file. For more information, see the yamlconfig page.

Command Line Options

This task supports additional command line options, including a .parameters collection for passing in options that are not directly supported. For more information, see the commandline task options documentation.