简体   繁体   中英

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 each 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:

在此处输入图像描述 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM