2

I am trying to build a solution file using C# code using WPF application. Please find the code snippet below:

var buildEngine = new Engine();
var project = new Project(buildEngine);
project.Load(<pathToCsProjFile>);
project.SetProperty("Configuration", "Debug");

var success = project.Build();    
if (success)
{
    MessageBox.Show("Build Succeeded");
}
else
{
    MessageBox.Show("Build Failed");
}

When I run the code above, variable "success" holds the value of false. Is there any way to capture the project output and display it in a textblock or any WPF control. I need to see the build errors if any in the application.

4

2 回答 2

4

是的,有一种方法可以查看所有构建错误,您需要实现ILogger接口并将该实例传递给Project.Build(ILogger)方法。

对于一个简单的示例,您可以查看msdn 页面示例部分。

于 2012-08-28T13:56:38.900 回答
1

在构建参数中,您可以提供这样的记录器

new BuildParameters() 
                {
                    DetailedSummary = true,
                    Loggers = new List<ILogger>(){logger}
                }

那么您将必须构建一个自定义记录器,该记录器输出到字符串或流,以便稍后您可以读取它

于 2012-08-28T14:19:05.427 回答