How to programmatically reverse an inline build of MsBuild

I am embedding MSBuild directly into a more complex build tool. The relevant code looks something like this:

// assume 'using Microsoft.Build.BuildEngine;'
Engine e = Engine();
BuildPropertyGroup props = new BuildPropertyGroup();
props.SetProperty( "Configuration", Config.BuildConfig );
e.BuildProjectFile( projectFile, new string[] { "Build" }, props )

      

My question is how to cancel this build once it has started without doing something abrupt like ending the thread. Also, if the built project is a C ++ project, the build will include at least one sub-process, so canceling the thread won't even really cancel the build.

I don't see a cancellation method in the Engine class. Does anyone know a way?

0


source to share


3 answers


There seems to be no official way to do this.

For C #, this isn't a huge deal as they tend to be very fast. The best workaround I have come up with for C ++ builds is to find the child processes created by the VC build process and terminate them, which stops the MSBuild build. This can be done using a Toolhelp32 snapshot, something like this (excluding the P / Invoke garbage):



CreateToolhelp32Snapshot( ToolHelp.SnapshotFlags.Process, 0 );

      

Here you can define the parent-child relationship between processes and find the processes spawned by the application calling MSBuild.

0


source


This question has popped up several times on MSDN boards and unfortunately I haven't seen any other way other than stopping the stream. Unfortunately, in this case, stopping the flow is not really radical as it is the only real option.



On the occasional side of the note, I'm not sure how much you are using MSBuild with what you are currently doing. Just wanted to recommend taking a look at the MSBuild Extension Pack at Codeplex if you work with MSBuild regularly.

+1


source


I did something similar by running msbuild from command. This will start a process that you can complete.

In my experience, it is much easier and more flexible to manipulate project files using xml tools and then execute msbuild than to programmatically configure your projects as you described. It's also more manageable.

0


source







All Articles