3

我正在使用下面的代码在蛋糕脚本中编译我的项目,并且我想在文本文件中获取构建日志。

if(IsRunningOnWindows())
{

  // Use MSBuild
  foreach(string currenproject in projectslocation)
  {
  MSBuild(currenproject, new MSBuildSettings()
  .SetConfiguration(configuration)
  .SetVerbosity(Verbosity.Minimal));

  }

}

这可以创建构建日志文件吗?

4

2 回答 2

5

在 Cake (0.17.0) 的下一个版本(希望我们在本周末发布)中,我们实现了这个功能请求,它允许使用一个新的扩展方法,它允许你传入一个MSBuildFileLogger。此扩展方法将防止需要走 ArgumentCustomization 路线。

这应该允许您执行以下操作:

MSBuild("./myproject.sln", new MSBuildSettings()
    .AddFileLogger(new MSBuildFileLogger {
        LogFile = "./errors.txt",
        MSBuildFileLoggerOutput = MSBuildFileLoggerOutput.ErrorsOnly   
});

您现在可以使用 Cake 的MyGet feed获得 Cake 的 v0.17.0 预发布版本。

如果您使用 nuget CLI 安装 Cake,就像在默认引导程序中所做的那样,您可以添加-Source https://www.myget.org/F/cake/api/v3/index.jsonnuget install语句中。

然后:

  • 如果您使用的package.config是固定 Cake 版本,请指定版本0.17.0-alpha0092或更高版本。

  • 如果您只使用Cake包 id 安装,那么您要么只需添加-PreRelease它,它就会从提要中获取最新版本,或者还指定-Version 0.17.0-alpha009参数。

于 2016-10-26T11:08:51.553 回答
2

您可以使用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));
    }
}
于 2016-10-26T10:59:07.840 回答