如何使用Nant检查文件是否包含某个字符串?

3

目前我正在调用findstr并将输出存储在属性中以便之后检查 - 我相信一定有更好的解决方案。

<exec program="findstr.exe"
    workingdir="${workspaceDir}"
    commandline='/i /c:"someText" ${fileName}'
    failonerror="false"
    output="${coverageExcludeLog}"
    resultproperty="foundFile"
/>

这真的是最好的做法吗?

1个回答

4
<loadfile file="${fileName}" property="MyFileContents" />

<property name="Mystring" value="someText" />

<property name="search.file" value="${string::contains(MyFileContents, Mystring)}" />
 <if test="${bool::parse(search.file)}" > <!-- true or false-->
  <echo message="Found the  string ${Mystring} in the file ${fileName}" />
 </if>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接