通过电子邮件发送 MSBuild 错误 - 仅当出现错误时

发布于 12-26 09:57 字数 698 浏览 3 评论 0原文

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小草泠泠2025-01-02 09:57:06

假设 ErrorFileContents 在发生错误时不为空,您可以迭代其项目来设置条件标志。

   <CreateProperty Value="true">
      <Output Condition="'%(ErrorFileContents.Identity)' != ''"
          TaskParameter="Value"
          PropertyName="SendMail" />
    </CreateProperty>

    <MSBuild.Community.Tasks.Mail Condition="'$(SendMail)' == true"
        SmtpServer="mailhost.amsa.com"
        To="$(ErrorEmails)"
        From="$(FromEmail)"
        Subject="Build failure for $(SolutionName)"
        Body="Error details: @(ErrorFileContents, '%0D%0A')"
       />

Assuming ErrorFileContents is not empty in case of an error, you can iterate through its items to set a condition flag.

   <CreateProperty Value="true">
      <Output Condition="'%(ErrorFileContents.Identity)' != ''"
          TaskParameter="Value"
          PropertyName="SendMail" />
    </CreateProperty>

    <MSBuild.Community.Tasks.Mail Condition="'$(SendMail)' == true"
        SmtpServer="mailhost.amsa.com"
        To="$(ErrorEmails)"
        From="$(FromEmail)"
        Subject="Build failure for $(SolutionName)"
        Body="Error details: @(ErrorFileContents, '%0D%0A')"
       />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文