Bin*_*ony 12
<?xml version="1.0" encoding="utf-8" ?>
<project xmlns="http://nant.sf.net/release/0.86-beta1/nant.xsd"
name="Company.Portal.Domain" default="GetFile">
<call target="GetFile" />
<target name="GetFile">
<echo message="Retrieving file contents"/>
<property name="file.contents" value="0" />
<loadfile file="file.txt" property="file.contents" />
<property name="file.contents" value="${string::trim(file.contents)}" />
<echo message="contents of file is ${file.contents}"/>
</target>
</project>
Run Code Online (Sandbox Code Playgroud)
当然,如果你愿意,你可以跳过第6,9和10行.[编辑]
<if test="${file.contents=='someValue'}">
<echo>Some value found</echo>
</if>
Run Code Online (Sandbox Code Playgroud)
在此链接获取完整的详细信息
[EDIT2]
由于您想获取文本文件第3行的值,请执行此操作
<?xml version="1.0"?>
<project name="Read3rdLine" default="main">
<property name="myInt" value="0"/>
<property name="x" value="0"/>
<property name="LineToRead" value="3"/>
<target name="main" description="compiles the source code">
<property name="i" value="0"/>
<foreach item="Line" in="file.txt" property="x" trim="Both">
<property name="i" value="${int::parse(i) + 1}"/>
<if test="${i==LineToRead}">
<property name="myInt" value="${x}"/>
</if>
</foreach>
<echo>found ${myInt} at line ${LineToRead}</echo>
</target>
</project>
Run Code Online (Sandbox Code Playgroud)