4

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!

Matt
  • 4,318
  • 1
  • 27
  • 28
junkyspace
  • 365
  • 4
  • 15

2 Answers2

5

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!

Matt
  • 4,318
  • 1
  • 27
  • 28
-3

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:

enter image description here 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!

lysergic-acid
  • 19,570
  • 21
  • 109
  • 218
  • Thanks, but I specifically asked about a particular interface. I already have a vspackage and am looking to deploy it to a bunch of developers; I'd rather not do macro hacks. – junkyspace Jul 15 '11 at 13:13