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

萝らか妹 提交于 2020-01-01 07:28:09

问题


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?


回答1:


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!" /> 


来源:https://stackoverflow.com/questions/757344/how-do-i-cause-an-error-in-msbuild-if-a-file-exists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!