开发者

How to access error details in MSBuild

开发者 https://www.devze.com 2023-03-02 00:36 出处:网络
I\'m creating MSBuild Project that will send a detailed email when an error occ开发者_StackOverflow社区urs. I am using a Mail Task from MsBuild Community Tasks package. But I don\'t know how to pass e

I'm creating MSBuild Project that will send a detailed email when an error occ开发者_StackOverflow社区urs. I am using a Mail Task from MsBuild Community Tasks package. But I don't know how to pass error details to this task - is there any predefined variable with error or something ?

<Target Name="All">
  <CallTarget Targets="DoSomething" />
  <OnError ExecuteTargets="ErrorEmail"/>
</Target>

<Target Name="ErrorEmail">
  <Mail SmtpServer="mysrv" From="me@mysrv" To="error@mysrv" Subject="An error occured"
      Body="Error details: " />
</Target>


The only predefined property would be $(MSBuildLastTaskResult), but it in your example will only ever have the value "false" which isn't useful. You'll need to either set up an error property inside DoSomething, or else ensure that a log file has been created (see msbuild file logger parameters) and send the log file contents in the email. Consider something like this:

> msbuild MyProject.proj /fl /flp:v=detailed;logfile=mylog.txt

<Target Name="ErrorEmail">
   <ReadLinesFromFile
      File="mylog.txt"
      Lines="_ErrorLines"
      />
   <Mail
      SmtpServer="mysrv"
      From="me@mysrv"
      To="error@mysrv"
      Subject="An error occured"
      Body="Error details: @(_ErrorLines, '%0D%0A')"
      />
</Target>
0

精彩评论

暂无评论...
验证码 换一张
取 消