当以编程方式运行MSBuild 4.0时,无法附加fileloglogger

本文关键字:fileloglogger 0时 编程 方式 运行 MSBuild | 更新日期: 2023-09-27 18:17:16

我试图在c#代码中运行MSBuild 4.0时获得日志。

var fileLogger = new Microsoft.Build.BuildEngine.FileLogger(){参数= @"C:'MSBuild.log")};

var projectCollection = new ProjectCollection();
var buildParamters = new BuildParameters(projectCollection);
buildParamters.Loggers = new List<Microsoft.Build.Framework.ILogger>() { new Microsoft.Build.BuildEngine.FileLogger() { Parameters = @"C:'MSBuild.log" }};
var globalProperty = new Dictionary<String, String>();
globalProperty.Add("Configuration", "Debug");
globalProperty.Add("Platform", "Any CPU");
BuildManager.DefaultBuildManager.ResetCaches();
var buildRequest = new BuildRequestData(projectFile, globalProperty, null, new String[] { "Clean", "Build" }, null);
var buildResult = BuildManager.DefaultBuildManager.Build(buildParamters, buildRequest);

然而,在构建完成之后(无论是成功还是失败),没有生成日志文件。我错过什么了吗?

当以编程方式运行MSBuild 4.0时,无法附加fileloglogger

问题是在传递给FileLogger的参数中,它应该是这样的,注意logfile=:

Parameters = @"logfile=c:'MSBuild.log"

见http://msdn.microsoft.com/en-us/library/microsoft.build.buildengine.consolelogger.parameters%28v=vs.121%29.aspx

除了stijn的回答:

下面是所有可用的参数:

日志文件

= C: ' LogPath ' LogFile.log; 添加, NoAutoFlush , 编码 = utf - 8;

默认值(如果未指定参数):

LogFile: msbuild.log(将在当前目录中创建,例如Directory.GetCurrentDirectory ())

Append: false (no Append)

NoAutoFlush: false(自动刷新开启)

编码: System.Text.Encoding.Default