我正在尝试在我的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);
但是,在构建完成后(成功或失败),不会生成任何日志文件。我错过了什么吗?
答案 0 :(得分:4)
问题在于传递给FileLogger的参数,它应该是这样的,请注意logfile=
:
Parameters = @"logfile=c:\MSBuild.log"
答案 1 :(得分:0)
除了 stijn的回答:
以下是所有可用参数:
<强>日志文件强> = C:\ LOGPATH \ LOGFILE.LOG;的追加强>的 NoAutoFlush 强>的编码 = UTF- 8;
默认值(如果未指定参数):
LogFile: msbuild.log (将在当前目录中创建,例如 Directory.GetCurrentDirectory())
追加: false (无附加)
NoAutoFlush: false (自动清除已开启)
编码: System.Text.Encoding.Default