views:

88

answers:

1

So I run my task with ccnet and my task creates files. What is the best way to read the file and identify if there is a certain value in it from msbuild??

+2  A: 

It's depend on your file.

Plain text with multiple lines

If the file is like that :

Building XXX
...
BUILD SUCCESSFUL
Total time: 38 seconds
Buildfile: file.

You could use ReadLinesFromFile to read the file and CreateProperty with a Condition to check the value.

<PropertyGroup>
  <ValueToCheck>BUILD SUCCESSFUL</ValueToCheck>
</PropertyGroup>

<Target Name="CheckValue">
  <ReadLinesFromFile File="@(MyTextFile)" >
    <Output TaskParameter="Result" ItemName="Value"/>
  </ReadLinesFromFile>

  <CreateProperty Value="true"
                  Condition="'%(Value.Identity)' == '$(ValueToCheck)'">
    <Output TaskParameter="Value" PropertyName="ValueIsPresent" />
  </CreateProperty>

</Target>

Xml file

If the file is in Xml, you could use XmlPeek (MSBuild 4) or XmlRead from MSBuild Community Task.

madgnome