How do I pass 2 parameters to Nant script?

Nick picture Nick · Feb 16, 2010 · Viewed 11.3k times · Source

I have to write an Nant script that will accept 2 parameters on the command line. The first is just an option and has the following format: -myOption. The second one needs to be wrapped in quotes: "some value with space".

e.g. -myOption "this value"

I am new to Nant so I have unsuccessful so far and don't know how to output the command to debug.

This is what I have so far:

<target name="Build" depends="SetupConfig">
<exec workingdir="${refactory.basedir}" program="${exe.name.mfg.factory}" basedir="${refactory.basedir}" commandline="-myOption:">  
 <arg>${refactory.clientconfig}</arg>   
</exec>

I am attempting to create the command using the "commandline"' attribute and the args nested element. The args element is supposed to provide qoutes.

Can some tell me how this should look? Thanks.

Answer

The Chairman picture The Chairman · Feb 16, 2010

I need to confess, looking at your code snippet it's not completely clear to me, what You are trying to achieve.

Anyway, this is how you pass two arguments to a NAnt script (what You're claiming for regarding to the question's title):

Given a NAnt script example.project.build with following content:

<?xml version="1.0"?>
<project name="example.project" default="example.target" basedir=".">
  <target name="example.target">
    <echo message="${arg.option}" />
    <echo message="${arg.whitespace}" />
  </target>
</project>

... you would call

nant -buildfile:example.project.build -D:arg.option=foo -D:arg.whitespace="bar and bar"

... to execute script example.project.build and pass arguments arg.option and arg.whitespace to it.