如何将exec的输出分配给NAnt中的属性

Nag*_*agg 8 cruisecontrol.net nant

我的目标是用命令"git describe"的输出来填充属性.我有一个属性:

<property name="build.version" value = ""/>
Run Code Online (Sandbox Code Playgroud)

我想用以下命令的输出填充它:git describe

我试过了:

<exec program='${git.executable}' outputproperty='build.version'>
  <arg value='describe' />
</exec>
Run Code Online (Sandbox Code Playgroud)

但与Ant不同,NAnt不支持outputproperty :(仅输出(到文件).

The*_*man 8

你是对的.您具有resultproperty保存退出代码和output属性的属性以重定向输出.

为什么不通过loadfile任务重定向输出并加载文件:

<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>
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,我已经完全一样了.我一直在寻找没有任何临时文件的解决方案:( (2认同)

小智 5

使用trim,你可以在最后摆脱回车符.例如,在上面的示例中,在末尾添加一条线来修剪字符串

<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>
Run Code Online (Sandbox Code Playgroud)