Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NAnt: How to get target name that was specified on command line

Tags:

.net

target

nant

From within my NAnt build script, I'm trying to find out the name of that target that was specified on the command line (or the default target if none was specified).

I've been reviewing the documentation at http://nant.sourceforge.net/release/0.85-rc1/help/functions/index.html#NAnt and can't seem to find anything. The only slightly related function I can find is target::get-current-target which returns the name of the target that I'm currently in, not the target that was specified on the command line.

Anyone know if there's a way to access this information? I couldn't find anything in NAntContrib either. Seems like it has to be there somewhere.

Thanks.

like image 345
goombaloon Avatar asked Jan 29 '11 16:01

goombaloon


1 Answers

Here is a simple function to see if the target was specified on the command line. Just call myFunctions::isTargetOnCommandLine('foo') substituting the name of your target.

<script language="C#" prefix="myFunctions" >
  <code>
    <![CDATA[
      [Function("isTargetOnCommandLine")]
  public static bool isTargetOnCommandLine(string target) {
    return (Array.IndexOf(Environment.GetCommandLineArgs(), target) != -1);
  }
    ]]>
  </code>
</script>   
like image 97
robertburke Avatar answered Sep 22 '22 06:09

robertburke