Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can an add-in detect when a solution is loaded?

How can my add-in detect when a solution is loaded? I know there must be some event somewhere in the DTE model, but I can't find it. My add-in loads when Visual Studio loads, but it depends on a solution being open. I don't want to make it a solution add-in until MS loses their sick fixation on COM, as solution add-ins have to be COM components.

like image 651
ProfK Avatar asked Feb 23 '09 14:02

ProfK


1 Answers

Here's how to register for event handling using C#:

_solutionEvents = _applicationObject.Events.SolutionEvents;
_solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionOpened);
_solutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(SolutionClosed);

Also note that when user opens Visual Studio by double clicking on a solution file, you won't get an event for solution opening. You should check whether _applicationObject.Solution is not null in OnStartupComplete method to handle this situation correctly.

like image 185
Juozas Kontvainis Avatar answered Oct 05 '22 22:10

Juozas Kontvainis