将警告消息记录在蛋糕脚本的文本文件中 [英] Log the warning messages in a text file from a cake script
问题描述
我正在使用下面的蛋糕脚本来编译我的 C#
项目。执行脚本时, PowerShell
中几乎没有显示警告消息。我想将警告记录在物理位置的文本文件中(例如: D:\WarningReport.txt)
。
下面是我用来编译项目的蛋糕脚本任务。
I'm using the below cake script to compile my C#
project. There are few warning messages shown in PowerShell
while executing the script. I like to log the warnings in a text file which is in a physical location(ex: D:\WarningReport.txt)
.
The below is the cake script task I use to compile the project.
Task("Build")
.Does(() =>
{
if(IsRunningOnWindows())
{
MSBuild("./src/Example.sln", settings =>
settings.SetConfiguration(configuration));
}
});
我喜欢在下面添加一些内容,
I like to add something like below,
LogWarningMessagesTo("D:\WarningReportes.txt");
LogErrorMessagesTo("D:\ErrorReportes.txt");
该怎么做?
推荐答案
如果是来自MSBuild别名的警告和错误,则要使用 AddFileLogger 扩展方法,位于 MSBuildSettings 参数。
If it's warnings and errors from MSBuild alias you want to log that's certainly possible using the AddFileLogger extension method on the MSBuildSettings parameter.
基本更改
MSBuild("./src/Example.sln", settings =>
settings.SetConfiguration(configuration));
到
MSBuild("./src/Example.sln", settings =>
settings.SetConfiguration(configuration)
.AddFileLogger(new MSBuildFileLogger {
LogFile ="D:/WarningReportes.txt",
MSBuildFileLoggerOutput = MSBuildFileLoggerOutput.WarningsOnly })
.AddFileLogger(new MSBuildFileLogger {
LogFile ="D:/ErrorReportes.txt",
MSBuildFileLoggerOutput = MSBuildFileLoggerOutput.ErrorsOnly })
);
这篇关于将警告消息记录在蛋糕脚本的文本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!