如何从msbuild获取构建日志?
我正在使用下面的代码编译我的项目在蛋糕脚本中,并且我想让生成日志文本文件。如何从msbuild获取构建日志?
if(IsRunningOnWindows())
{
// Use MSBuild
foreach(string currenproject in projectslocation)
{
MSBuild(currenproject, new MSBuildSettings()
.SetConfiguration(configuration)
.SetVerbosity(Verbosity.Minimal));
}
}
这是可以创建生成日志文件吗?
即将在蛋糕(0.17.0或更新)(希望这将我们在本周月底发布)的下一个版本,我们实现了这个feature request它允许新的扩展方法的使用,让您通过在MSBuildFileLogger。这种扩展方法将防止需要去参数定制路线。
这应该让你喜欢的东西:
MSBuild("./myproject.sln", new MSBuildSettings()
.AddFileLogger(new MSBuildFileLogger {
LogFile = "./errors.txt",
MSBuildFileLoggerOutput = MSBuildFileLoggerOutput.ErrorsOnly
});
可以使用Cake的MyGet feed获得蛋糕的预发布版本v0.17.0今天。
如果您使用nuget CLI来安装Cake,如所做的那样,您可以将-Source https://www.myget.org/F/cake/api/v3/index.json
添加到nuget install
语句中。
然后:
如果您使用的是
package.config
引脚蛋糕的版本,则指定0.17.0-alpha0092
或更高版本。如果只安装使用
Cake
包ID,那么你要么只是添加-PreRelease
,它会从饲料获取最新版本,或者也可以指定-Version 0.17.0-alpha009
参数。
您可以使用WithLogger(MSBuildSettings, string loggerAssembly, string loggerClass, string loggerParameters) MSBuildSettings扩展方法,该方法可用于指定自定义MSBuild日志记录。
目前没有可用的MSBuild标准文件记录器设置,但仍可以使用ArgumentCustomization。
if(IsRunningOnWindows())
{
DirectoryPath logPath = MakeAbsolute(Directory("./logfiles"));
// Use MSBuild
foreach(string currenproject in projectslocation)
{
FilePath logFile = logPath.CombineWithFilePath(string.Format(
"{0}.log",
currenproject));
MSBuild(currenproject, new MSBuildSettings {
ArgumentCustomization = args=>args.Append(
"/flp:\"logfile={0};verbosity={1}\"",
logFile.FullPath,
Verbosity.Diagnostic
)
}.SetConfiguration(configuration)
.SetVerbosity(Verbosity.Minimal));
}
}
@vijay是你在找什么?这是一个很好的问题,请评论任何不清楚的东西,我会尽力澄清。 – devlead
这很棒! – devlead