Reputation: 51063
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.
Upvotes: 5
Views: 2993
Reputation: 9597
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.
Upvotes: 8
Reputation: 5750
You have in the DTE2 class a property called Events
it gives a lots kind of events, for what you need you have to use:
DTE2 _applicationObject
_applicationObject.Events.SolutionEvents.Opened+=new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened);
Upvotes: 0