views:

261

answers:

2

Hi,

I'm trying to write an add-in for Visual Studio that needs to be run every time a solution is loaded. Eventually I hope to make it a solution add-in so that it only runs for solutions that need it, but I'm wondering if there's any way to have my add-in hook on the user loading a solution?

Thanks.

+1  A: 

The VCProjectEngineEvents SolutionLoaded event.

Edit: I can only hope somebody else can come up with a sample they can post -- the only relevant code I have is something I can't post.

Jerry Coffin
That's great! I'm a bit unfamiliar to C#, though, so could I possibly trouble you for an example of how you register a hook? Thanks.
coppro
A: 

You can use Saver add-in source code as an example (it is an add-in for the Tabs Studio add-in):
In Saver.cs you subscribe for events:

solutionEventsSink = new SolutionEventsSink(orderController);
System.IServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
vsSolution = ServiceProvider.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsSolution)) as Microsoft.VisualStudio.Shell.Interop.IVsSolution;
vsSolution.AdviseSolutionEvents(solutionEventsSink, out sinkCookie);

In SolutionEventsSink.cs are actual solution events handlers:

class SolutionEventsSink : Microsoft.VisualStudio.Shell.Interop.IVsSolutionEvents
Sergey Vlasov