SARAVAN
SARAVAN

Reputation: 15111

MSBUILD output using C#

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.

Upvotes: 2

Views: 526

Answers (2)

Parv Sharma
Parv Sharma

Reputation: 12705

in the build parameters you can provide a logger like this

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

then you will have to build a custom logger that outputs to a string or a stream so that later you can read it

Upvotes: 1

SynerCoder
SynerCoder

Reputation: 12786

Yes there is a way to see all the build errors, you need to implement the ILogger interface and pass that instance to the Project.Build(ILogger) method.

For a simple example you can check the msdn page example section.

Upvotes: 4

Related Questions