Email Errors in MSBuild - ReadLinesFromFile “is being used by another process”

笑着哭i 提交于 2020-01-04 15:20:08

问题


I'm trying to implement the answer from here: How to access error details in MSBuild

> 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>

Looks elegant, but I'm getting this error:

c:\AccuRev\Build_2012_01_02\MyApp\ErrorHandlers.targets(24,9): error MSB3501: Could not read lines from file "mylog.txt". The process cannot access the file 'c:\AccuRev\Build_2012_01_02\MyApp\mylog.txt' because it is being used by another process


回答1:


mylog.txt file is locked because you are using the same file for build log and for the ReadLinesFromFile task.

EDIT: Try to execute MSBuild 2 times. First to build your projects and 2nd time to send an email. Use distributedFileLogger command line switch with /flp1:logfile=errors.txt;errorsonly command line parameters to log all errors to errors.txt. You can then attach this file into your email without sending whole build log.




回答2:


I know it's late for the party, but I was struggling with this myself: How to access the error log in order to attach it to an email? Was getting the same message--the error log file couldn't be accessed to attach it, or even to read it.

The solution? Copy the log file and then send the copy. Worked like a charm. My code looks something like this:

<Target Name="FailBuild">
  <Copy SourceFiles="errors.txt" DestinationFiles="errors_email.txt" />
  <Mail SmtpServer="$(SmtpEmailServer)"
      ...
      Attachments="errors_email.txt" />
</Target>


来源:https://stackoverflow.com/questions/8728883/email-errors-in-msbuild-readlinesfromfile-is-being-used-by-another-process

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