Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I cause an error in MSBuild if a file exists?

Tags:

msbuild

We have a process that runs prior to our nightly builds. If the process fails it generates a text file. All I need to do is check to see if the file exists, and if it does, cause a failing MSBuild.

I currently have tried the following:

<CreateProperty Condition="Exists('C:\Process\Fail.txt')"
      Value="false">
  <Output TaskParameter="Value" PropertyName="ProcessTestPassed"/>
</CreateProperty>
<Message Text="Process did not pass" Condition="Exists('C:\Process\Fail.txt')" ContinueOnError="false" />

<ReadLinesFromFile File="C:\Process\Fail.txt"                  Condition="'$(ProcessTestPassed)'=='false'" ContinueOnError="false" >
  <Output TaskParameter="Lines" ItemName="FileContents" />
</ReadLinesFromFile>
<Message Text="FileContents: $(FileContents)"  Condition="'$(ProcessTestPassed)'=='false'" ContinueOnError="false" />

Which gives a passing build with this output:

Task "CreateProperty"
Done executing task "CreateProperty".
Task "Message"
  QAWizardProTestPassed did not pass
Done executing task "Message".
Task "ReadLinesFromFile"
Done executing task "ReadLinesFromFile".
Task "Message"
  FileContents: 
Done executing task "Message".

I know the above is probably overkill, but I just need something working! What am I missing here?

like image 536
dprice Avatar asked Apr 16 '09 18:04

dprice


1 Answers

As noted by @dprice in his comment, the best solution for this would be:

<Error Condition="Exists('C:\Process\Fail.txt')" Text="Process did not pass!" /> 
like image 95
Bruno Lopes Avatar answered Oct 18 '22 21:10

Bruno Lopes