7

From a visual studio package (VSIX) how do I detect a solution or project build?

Simon
  • 33,714
  • 21
  • 133
  • 202

2 Answers2

4

If you have a Package class in your assembly, you can do:

DTE2 = Package.GetGlobalService(typeof(SDTE)) as DTE2;

Then look at then IsOpen property, to see if the solution is open... the look at the Projects property to find the projects.

However, if you mean you how do I get an event when a solution is opened... then Solutions, for example:

public sealed class MyPackage : Package
{
  private DTE m_dte;

  protected override void Initialize()
  {
    IServiceContainer serviceContainer = this as IServiceContainer;
    m_dte = serviceContainer.GetService(typeof(SDTE)) as DTE;
    var m_solutionEvents = m_dte.Events.SolutionEvents;
    m_solutionEvents.Opened += SolutionOpened;
    ...

  }

  void SolutionOpened()
  {
     .... away you go...
  }
}

ref: VSIX: Getting DTE object ref: http://msdn.microsoft.com/en-us/library/envdte.solution.aspx

ref: http://msdn.microsoft.com/en-us/library/envdte._solution.projects.aspx

Stephen Gennard
  • 1,910
  • 16
  • 21
  • 1
    Looking at this page on MSDN: http://msdn.microsoft.com/en-us/library/envdte.solutionevents(v=vs.100).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1; all of the events are labelled "Infrastructure. Microsoft Internal Use Only." Does that mean they shouldn't be used in a VS package? – Aaron Campbell Oct 03 '14 at 21:05
  • 1
    I don't think this answers the OP's question (and I have the same question), which is how would one detect a BUILD event? You have shown how to detect a SolutionOpened event. – Rob B Jul 04 '16 at 15:56
  • how do I access the compiled dlls (projects)? I'm writing an extension that depends on the compiled projects, that is, the extension will read metadata from the assemblies – JobaDiniz Sep 21 '19 at 19:29
2

Have a look at DTE.Events.BuildEvents there are events for OnBuildBegin and OnBuildDone.

Daniel Fisher lennybacon
  • 3,865
  • 1
  • 30
  • 38