开发者

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:

  1. Hit Alt-F11 (shortcut for the Macro editor, and we all know keyboard shortcuts are cool).
  2. From Project Explorer, double click EnvironmentEvents.
  3. From the left dropdown (where it says General), select BuildEvents:

How to get IVsBuildableProjectCfg to subscribe to build events?

4. From the right dropdown, select the event you're interested in (OnBuildDone for example). 5. A new Sub is added, place the code you'd like to run when a build is done. 6. Save, and close the Macro editor. 7. Build your project. The code you entered should execute once the build is done.

Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜