我有一个我想从MSBuild项目调用的批处理脚本,文档说我不能使用MSBuild项目中批处理(控制台/环境变量)的输出.
有解决方法吗?
当我在命令行运行msbuild时,它在控制台中显示漂亮的颜色.
但是当我从C#中运行时Process.Start,输出显示为黑白.我该如何保持颜色?
var info = new ProcessStartInfo("msbuild")
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
};
using (var p = Process.Start(info) )
{
p.ErrorDataReceived += (s, e) => Console.Error.WriteLine(e.Data);
p.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
p.BeginErrorReadLine();
p.BeginOutputReadLine();
p.WaitForExit();
}
Run Code Online (Sandbox Code Playgroud)
而且,虽然我们在这里,但它比我Process.Start之前 运行的重要BeginOutputReadLine吗?输出会丢失吗?
动机,对于那些感兴趣的人.我工作的项目使用自定义构建工具(重新发明轮子imho).它使用msbuild但在复杂的间接层之后(上面的简化模型).Msbuild的有用颜色丢失了.我想保存它们.
我有以下exec任务,执行assemblyinfo.cs文件的签入.我正在尝试返回退出代码,但由于某种原因它总是空的.
<!--Checkin if all succeeded-->
<Exec Condition=" '$(LocalCompilationSuccess)' != 'Failed' and '$(LocalTestSuccess)' != 'Failed' " ContinueOnError="True"
Command='"$(TfCommand)" checkin /recursive /comment:"$(NoCICheckInComment) $(BuildDefinitionName): build succeeded, checkin changes." /override:"TeamBuild $(BuildDefinitionName)" $/SomeProject/Trnk' WorkingDirectory="$(SolutionRoot)" >
<Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
</Exec>
Run Code Online (Sandbox Code Playgroud)
我试图以两种方式阅读退出代码:
'%(ErrorCode.Identity)'
'$(ErrorCode)'
Run Code Online (Sandbox Code Playgroud)
两者都是空的.有什么建议?
我有一个正在进行部署的python脚本.我想从msbuild运行该脚本并获取输出,以防它通过或失败.那么,如何与msbuild进行状态通信和错误文本?我想在构建服务器上显示结果.我必须使用python 2.7,并且不能使用3.x.