首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如果exitCode =0但有日志记录到标准错误,msbuild中的执行任务会失败吗?

如果exitCode =0但有日志记录到标准错误,msbuild中的执行任务会失败吗?
EN

Stack Overflow用户
提问于 2021-07-28 23:49:27
回答 1查看 22关注 0票数 0

我很好奇:

https://docs.microsoft.com/en-us/visualstudio/msbuild/exec-task?view=vs-2019

ExitCode可选的Int32输出只读参数。

指定由执行的命令提供的退出代码,但如果任务记录了任何错误,但进程的退出代码为0(成功),则ExitCode将设置为-1。

即使进程的退出代码为0,但它记录到标准错误,msbuild在Exec上也会失败吗?

我试着用下面的代码让它失败:

代码语言:javascript
运行
复制
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
   class Program
   {
      static int Main( string[] args )
      {
         using ( var stdErr = Console.Error )
         {
            for ( int i = 0; i <= 100; i++ )
            {
               stdErr.WriteLine( $"Failed to copy attempt {i}." );
               System.Threading.Thread.Sleep( 50 );
            }

            // Close redirected error stream.
            Console.Error.Close();
         }
         return 0;
      }
   }
}

它被作为标准props文件的一部分来调用。

代码语言:javascript
运行
复制
   <Target 
          Name = "IvaraSign"
          AfterTargets="CoreBuild"
          BeforeTargets="CopyFilesToOutputDirectory" >
     <!-- Update version on main output -->
     <!-- this works when the solution being compiled is in the dotnet folder. -->
     <Exec Command="C:\Users\Derek.Morin\source\repos\ConsoleApp3\bin\Debug\ConsoleApp3.exe"/>
  </Target>

当我在msbuild中构建时,我可以在构建输出中看到错误文本,但是编译通过了。

EN

Stack Overflow用户

回答已采纳

发布于 2021-07-28 21:07:16

Does the MSBuild Exec task search STDOUT for the string "error"?

我可以复制使exec文件失败,并显示以下内容

代码语言:javascript
运行
复制
  static int Main( string[] args )
  {
     using ( var stdErr = Console.Error )
     {
        stdErr.WriteLine( $@"signtool.exe : error information: ""Error: Store IsDiskFile() failed."" (-2147024864/0x80070020) [d:\work\1\s\common\MAFPlugins\MAFScripting\Contracts\Contracts.csproj]" );
     }
     Console.WriteLine( "but I'm still going to return 0" );
     return 0;
  }

解决方法是使用IgnoreStandardErrorWarningFormat="true“。

代码语言:javascript
运行
复制
<Exec Command="C:\ConsoleApp3\ConsoleApp3.exe" IgnoreStandardErrorWarningFormat="true" />
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68563563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档