3

I am wanting to run MSBUILD through code, and get asynchronous status of the build as it progresses (similar to TeamCity or any other build runner does).

I am using the following code:

var projectFileName = @"...\MyApplication\MyApplication.sln"; ProjectCollection pc = new ProjectCollection(); var GlobalProperty = new Dictionary<string, string>(); GlobalProperty.Add("Configuration", "Debug"); GlobalProperty.Add("Platform", "x86"); var buildRequest = new BuildRequestData(projectFileName, GlobalProperty, null, new string[] { "Build" }, null); var buildResult = BuildManager.DefaultBuildManager.Build(new BuildParameters(pc), buildRequest); 

Is there a way to get the current executing MSBUILD task through code?

1 Answer 1

10

you have to call build asyncronously and to test iscomplete in a loop where you can make your progress tracking:.

private void button1_Click(object sender, EventArgs e) { var projectFileName = @"...\MyApplication\MyApplication.sln"; ProjectCollection pc = new ProjectCollection(); var GlobalProperty = new Dictionary<string, string>(); GlobalProperty.Add("Configuration", "Debug"); GlobalProperty.Add("Platform", "x86"); BuildManager.DefaultBuildManager.BeginBuild(new BuildParameters(pc)); BuildRequestData request = new BuildRequestData(projectFileName, GlobalProperty, null, new string[] { "Build" }, null); BuildSubmission submission = BuildManager.DefaultBuildManager.PendBuildRequest(request); submission.ExecuteAsync(null, null); int cpt = 0; while (!submission.IsCompleted) { cpt++; textBox1.Text = cpt.ToString(); } BuildManager.DefaultBuildManager.EndBuild(); // If the build failed, return an error string. if (submission.BuildResult.OverallResult == BuildResultCode.Failure) { //do some error task } } 
Sign up to request clarification or add additional context in comments.

1 Comment

I was actually considering setting up a MSBUILD log provider and watching it for build complete messages?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.