Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 742
Simon Avatar asked Apr 27 '11 13:04

Simon


2 Answers

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

like image 95
Stephen Gennard Avatar answered Oct 20 '22 07:10

Stephen Gennard


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

like image 29
Daniel Fisher lennybacon Avatar answered Oct 20 '22 08:10

Daniel Fisher lennybacon