我很好奇:
https://docs.microsoft.com/en-us/visualstudio/msbuild/exec-task?view=vs-2019
ExitCode可选的Int32输出只读参数。
指定由执行的命令提供的退出代码,但如果任务记录了任何错误,但进程的退出代码为0(成功),则ExitCode将设置为-1。
即使进程的退出代码为0,但它记录到标准错误,msbuild在Exec上也会失败吗?
我试着用下面的代码让它失败:
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文件的一部分来调用。
<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中构建时,我可以在构建输出中看到错误文本,但是编译通过了。
发布于 2021-07-28 21:07:16
Does the MSBuild Exec task search STDOUT for the string "error"?
我可以复制使exec文件失败,并显示以下内容
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“。
<Exec Command="C:\ConsoleApp3\ConsoleApp3.exe" IgnoreStandardErrorWarningFormat="true" />
https://stackoverflow.com/questions/68563563
复制相似问题