通过电子邮件发送 MSBuild 错误 - 仅当出现错误时
msbuild MyProject.proj /fl /flp:v=detailed;logfile=mylog.txt
msbuild MyProject.proj /t:ErrorEmail
我已经实现了这个,并且在出现错误时它可以工作。 但如果没有错误,它也会发送电子邮件。 如果文件为空,或者 ReadLinesFromFile 中的行数为 0,如何设置条件?
> <Target Name="ErrorEmail">
> <ReadLinesFromFile
> File="mylog.txt"
> Lines="_ErrorLines"
> />
> <MSBuild.Community.Tasks.Mail
> SmtpServer="mailhost.amsa.com"
> To="$(ErrorEmails)"
> From="$(FromEmail)"
> Subject="Build failure for $(SolutionName)"
> Body="Error details: @(ErrorFileContents, '%0D%0A')"
> />
> </Target>
msbuild MyProject.proj /fl /flp:v=detailed;logfile=mylog.txt
msbuild MyProject.proj /t:ErrorEmail
I have implemented this, and it works when there are errors.
But it's also sending an email when there are no errors.
How can I set up a condition if the file is empty, or there are 0 line count in the ReadLinesFromFile?
> <Target Name="ErrorEmail">
> <ReadLinesFromFile
> File="mylog.txt"
> Lines="_ErrorLines"
> />
> <MSBuild.Community.Tasks.Mail
> SmtpServer="mailhost.amsa.com"
> To="$(ErrorEmails)"
> From="$(FromEmail)"
> Subject="Build failure for $(SolutionName)"
> Body="Error details: @(ErrorFileContents, '%0D%0A')"
> />
> </Target>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

假设 ErrorFileContents 在发生错误时不为空,您可以迭代其项目来设置条件标志。
Assuming ErrorFileContents is not empty in case of an error, you can iterate through its items to set a condition flag.