Question

My aim is to fill property with output of command "git describe". I have a property:

<property name="build.version" value = ""/>

And I want to fill it with output of the following command: git describe

I tried:

<exec program='${git.executable}' outputproperty='build.version'>
  <arg value='describe' />
</exec>

but unlike the Ant, NAnt doesn't support outputproperty :( only output (to file).

Était-ce utile?

La solution

You're right. You have resultproperty attribute to hold the exit code and output attribute to redirect the output.

Why don't you redirect the output and load the file afterwards via loadfile task:

<target name="foo">
  <property
    name="git.output.file"
    value="C:\foo.txt" />
  <exec program="${git.executable}" output="${git.output.file}">
    <arg value="describe" />
  </exec>
  <loadfile
    file="${git.output.file}"
    property="git.output" />
</target>

Autres conseils

Using trim, you can get rid of the carriage return character at the end. For instance, in the example above, add a line at the end to trim the string

<target name="foo">
  <property
    name="git.output.file"
    value="C:\foo.txt" />
  <exec program="${git.executable}" output="${git.output.file}">
    <arg value="describe" />
  </exec>
  <loadfile
    file="${git.output.file}"
    property="git.output" />

  <property name="git.ouput.trimmed" value="${string::trim(git.output)}" />

</target>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top