ProfK
ProfK

Reputation: 51063

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.

Upvotes: 5

Views: 2993

Answers (3)

Juozas Kontvainis
Juozas Kontvainis

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

Pablo Retyk
Pablo Retyk

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

Richard
Richard

Reputation: 108975

The SolutionEvents class on MSDN includes event:

Opened: Occurs immediately after opening a solution or project.

Upvotes: 0

Related Questions