You can use EnvDTE.Events.BuildEvents.OnBuildBegin
and OnBuildDone
.
Note that Every time you say dte.Events.BuildEvents
you're creating a new COM object behind the scenes that is garbage collected even if you still have an event listener on it. So save the BuildEvents object into a member variable somewhere before attaching your event handlers to it (so that it doesn't get garbage collected while you're using it).
You could also implement Microsoft.VisualStudio.Shell.Interop.IVsBuildStatusCallback
(and hook it into VS via AdviseBuildStatusCallback
) if you're sick of EnvDTE :P
Edit: Both of those run on the UI thread, but upon further reflection I think it might be too late at that point to modify the build itself (MSBuild may have already been sent the files and started building asynchronously). I'm not sure.