Twenty
Twenty

Reputation: 5901

Access build events without using DTE

When capturing build events you can simply listen to the DTE2.Events.BuildEvents event. However is it possible to listen to these events without the use of DTE. I have read and heard from several people and sources that you should generally avoid using DTE, if somehow possible, due to its bad implementation or whatever.

Upvotes: 0

Views: 240

Answers (2)

Twenty
Twenty

Reputation: 5901

I just want to share the code which actually works and achieves exactly what I needed. This was possible through the help of @Rich N, thanks for that one. It is actually easier than I thought, it is always the same procedure

  1. Get the Svs... class from the GetService method and cast it to the corresponding interface.
  2. Than append the Event Handler Class with the Advise... method.
// First of get the IVsSolutionBuildManager via the SVsSolutionBuildManager with the GetService method
var service = GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;

// Appending the Events
service.AdviseUpdateSolutionEvents(new Events(), out var cookie)

// The class which handles the Event callbacks
public class Events : IVsUpdateSolutionEvents
{
   // The implemented methods from the interface
}

Upvotes: 0

Rich N
Rich N

Reputation: 9475

In general if you're trying to automate Visual Studio you can either use DTE, which is the standard automation approach, or use native interfaces. The native interfaces start 'IVs...', e.g. IVsSolution. In both cases the technology is ancient and poorly-documented. As you suggest, a native solution does tend to be better.

Having said that, for the tasks running on a build that I've needed I ended up using DTE, which can be easier to program and made to work reliably.

I've found the equally-ancient articles (not the tools!) on the mztools.com website to be quite useful on this stuff, as well as the MSDN docs of course. Add 'mztools' to your Google search. For example, what mztools says on build events (Google 'mztools build events') is useful even though it dates from 2013.

Upvotes: 1

Related Questions