以编程方式运行MSBuild 4.0时无法附加FileLogger

时间:2014-08-08 07:37:50

标签: c# msbuild msbuild-4.0

我正在尝试在我的C#代码中运行MSBuild 4.0时获取日志。

var fileLogger = new Microsoft.Build.BuildEngine.FileLogger(){Parameters = @“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);

但是,在构建完成后(成功或失败),不会生成任何日志文件。我错过了什么吗?

2 个答案:

答案 0 :(得分:4)

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

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

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

答案 1 :(得分:0)

除了 stijn的回答:

以下是所有可用参数:

  

<强>日志文件 = C:\ LOGPATH \ LOGFILE.LOG;的追加 NoAutoFlush 编码 = UTF- 8;

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

  

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

     

追加: false (无附加)

     

NoAutoFlush: false (自动清除已开启)

     

编码: System.Text.Encoding.Default