How to get IVsBuildableProjectCfg to subscribe to the event assembly?

I am trying to get an instance of an IVsBuildableProjectCfg object, but I don't know how to get it.

Currently, I can get a DTE project and / or an IVsHierarchy object representing every active project, no problem. How do you get an IVsBuildableProjectCfg instance for each project?

Ideally, I want to connect to the build event of each project to find out if each build was successful or not, and also connect to the solution to see if the full build was completed.

(I also tried using DTE2.BuildEvents , but my handler never worked when I started the debugger.)

Thanks!

+4
source share
2 answers

Here you can get the active IVsBuildableProjectCfg for the 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 create events using:

  uint pdwCookie; ppIVsBuildableProjectCfg.AdviseBuildStatusCallback(new MyBuildStatusCallback(), out pdwCookie); 

Where MyBuildStatusCallback is the object you create that implements IVsBuildStatusCallback .

Hope this helps!

+5
source

You can do this with some macro programming:

  • Hit Alt-F11 (shortcut for the macro editor, and we all know that keyboard shortcuts are quick).
  • In Project Explorer, double-click the EnvironmentEvents icon.
  • In the drop-down menu on the left (where General is indicated), select BuildEvents:

enter image description here 4. In the right drop-down list, select the event you are interested in (for example, OnBuildDone). 5. Added a new Sub, put the code that you want to run when the build is complete. 6. Save and close the macro editor. 7. Create your own project. The code you entered should run after the build is complete.

Hope this helps!

-3
source

All Articles