我尝试在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);


但是,在构建完成(成功或失败)之后,未生成任何日志文件。我有想念吗?

最佳答案

问题出在传递给FileLogger的Parameters中,应该是这样,注意logfile=

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


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

关于c# - 以编程方式运行MSBuild 4.0时无法附加FileLogger,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25198279/

10-10 09:43