How to get IVsBuildableProjectCfg to subscribe to build events?
I am trying to get an instance of the IVsBuildableProjectCfg
object, but I have no clue how to get it.
I currently can get the DTE Project and/or the IVsHierarchy
object representing each active project without a problem. How do you get an instance of IVsBuildableProjectCfg
per project?
Ideally, I want to hook into the build event of eac开发者_如何学Goh project to know whether or not each build is successful, as well as hooking into the solution to see if the overall build was fired.
(I also tried using the DTE2.BuildEvents
, but my handler would never fire when I ran the debugger.)
Thanks!
Here's how you can get the active IVsBuildableProjectCfg
for a given IVsHierarchy
which I call ppHierarchy
below:
IVsSolutionBuildManager buildManager = (IVsSolutionBuildManager)GetService(typeof(SVsSolutionBuildManager));
IVsProjectCfg[] ppIVsProjectCfg = new IVsProjectCfg[1];
buildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, ppHierarchy, ppIVsProjectCfg);
IVsBuildableProjectCfg ppIVsBuildableProjectCfg;
ppIVsProjectCfg[0].get_BuildableProjectCfg(out ppIVsBuildableProjectCfg);
Then you can subscribe to build events using:
uint pdwCookie;
ppIVsBuildableProjectCfg.AdviseBuildStatusCallback(new MyBuildStatusCallback(), out pdwCookie);
Where MyBuildStatusCallback
is an object you create that implements IVsBuildStatusCallback
.
I hope this helps!
You can do this with some macro programming:
- Hit Alt-F11 (shortcut for the Macro editor, and we all know keyboard shortcuts are cool).
- From Project Explorer, double click EnvironmentEvents.
- From the left dropdown (where it says General), select BuildEvents:
Hope this helps!
精彩评论