我有一个用于构建.net解决方案的批处理文件,我正在尝试将详细级别设置为最小,它只显示正在构建的项目以及任何警告和/或错误,但也希望看到最后的摘要,其中包括警告和错误的数量以及构建时间。
我尝试了冗余和/v和/cpl的多种组合,但似乎只能得到太多的输出+摘要或正确的最小输出而没有摘要
有什么想法吗?
提前感谢
发布于 2014-01-29 04:39:04
您可以编写一个自定义记录器,如下所述:http://msdn.microsoft.com/en-us/library/ms171471.aspx
下面是一些代码,可以让您开始使用:
public class SummaryLogger : Logger
{
int warningCount = 0;
int errorCount = 0;
public override void Initialize(IEventSource eventSource)
{
eventSource.WarningRaised += eventSource_WarningRaised;
eventSource.ErrorRaised += eventSource_ErrorRaised;
eventSource.BuildFinished += eventSource_BuildFinished;
}
void eventSource_WarningRaised(object sender, BuildWarningEventArgs e)
{
warningCount++;
Console.WriteLine("Warning: " + e.Message);
}
void eventSource_ErrorRaised(object sender, BuildErrorEventArgs e)
{
errorCount++;
Console.WriteLine("Error: " + e.Message);
}
void eventSource_BuildFinished(object sender, BuildFinishedEventArgs e)
{
Console.WriteLine("MSBuild Finished: " + errorCount + " errors | " + warningCount + " warnings.");
}
}这个记录器记录警告,错误,并汇总错误和警告的数量。您需要为时间和项目添加一些代码,以便它恰好是您想要的。
要使用它,您需要调用添加了以下参数的MSBuild:
/nologo /noconsolelogger /logger:pathTo/SummaryLogger.dll发布于 2014-02-02 00:23:51
一种想法是从日志文件中提取所需的信息。
像这样,
Step 1: Redirect your msbuild outputs to a log.txt
Step 2: At the end of the batch file run findstr cmd to look for desired text示例:
@echo off
setlocal
...
MSBuild /nologo [path to project1 or sln1] [options] >> log.txt
...
MSBuild /nologo [path to project2 or sln2] [options] >> log.txt
...
findstr /irc:"Build*" /c:".*Warning(s)" /c:".*Error(s)" /c:"Time Elapsed.*" log.txt希望这能有所帮助!
https://stackoverflow.com/questions/7729030
复制相似问题