Search code examples
c#visual-studiovsix

VSIX Detect that a solution has been created


While Microsoft makes it "reasonably easy" to determine when a solution has been opened or closed in a VSIX extension

  IVsSolution.GetSolutionInfo(
out pbstrSolutionDirectory, 
out pbstrSolutionFile, 
out pbstrUserOptsFile);

I am puzzling how exactly in a VSIX extension can I get information / event on when a new solution is created. Is such a thing possible?

I'm assuming there must be some way to do this, but as the Microsoft extension documentation is sparse, I cannot find it.


Solution

  • Use the IVsSolutionEvents.OnAfterOpenSolution(Object, Int32) method, whose second parameter, fNewSolution is what you want: true if the solution is being created. false if the solution was created previously or is being loaded.

    You get IVsSolutionEvents with the IVsSolution.AdviseSolutionEvents(IVsSolutionEvents, UInt32) / IVsSolution.UnadviseSolutionEvents(UInt32) methods

    I created a working VSIX sample some time ago HOWTO: Get solution events from a Visual Studio package