I have been trying to build a solution using MSbuild API since few weeks now without success. I was able to build the solution by running a batch file inside my program that execute MSBUild.exe but I noticed that this is not a really good way of doing it. I googled a little and implemented the following code:
using Microsoft.Build.Execution;
public static String BuildProject(String projectPath)
{
try
{
var props = new Dictionary<string, string>();
props["Configuration"] = "Debug";
props["VisualStudioVersion"] = "12.0";
var request = new BuildRequestData(projectPath, props, null, new string[] { "Build" }, null);
var parms = new BuildParameters();
var result = BuildManager.DefaultBuildManager.Build(parms, request);
return result.OverallResult.ToString();
}
catch(Exception ex)
{
return ex.ToString();
}
}
When I run my program a bin folder with a debug folder inside is created but the nothing happened. Using the batch file it takes around 2-5 mins to build the project. Is there anything that I am missing ?