4

My Visual Studio Extension responds to the opening of a solution via IVsSolutionEvents.OnAfterOpenSolution().

Visual Studio 2017 introduced "Open Folder" as an alternative to "Open Solution", but when you open a folder, IVsSolutionEvents.OnAfterOpenSolution() doesn't fire. (Nor do any of the other events in IVsSolutionEvents, nor any of the events in IVsSolutionLoadEvents.)

How can my extension know when a Folder, as opposed to a Solution, is opened?

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
  • Are you looking for IVsSolutionEvents7::OnAfterOpenFolder? https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.interop.ivssolutionevents7?view=visualstudiosdk-2017 – Simon Mourier Sep 24 '17 at 16:12
  • @SimonMourier: That looks perfect, but when I implement it and pass my implementing object to `IVsSolution.AdviseSolutionEvents()`, none of the `IVsSolutionEvents7` events fires. The object also implements `IVsSolutionEvents`, and those events do fire. Any ideas...? – RichieHindle Sep 24 '17 at 17:35
  • Nope, I guess this is really the only way. Some VS dll implement that interface just like that (for example Microsoft.VisualStudio.Shell.UI.Internal, class Microsoft.VisualStudio.PlatformUI.StartPageToolWindowPane). You could try to implement ICustomQueryInterface temporarily just to check if it's even requesting that interface. – Simon Mourier Sep 25 '17 at 05:30
  • @SimonMourier: Aha! Implementing ICustomQueryInterface revealed that I needed to add `[ComVisible(true)]` to my definition of `IVsSolutionEvents7`. After that (and some more COM hoop-jumping) it's now all working - thanks! If you'd like to create an answer from your comment, I'd be delighted to accept it and award it a bounty (when it becomes eligible). – RichieHindle Sep 25 '17 at 22:31

1 Answers1

6

You have to use the IVsSolutionEvents7.OnAfterOpenFolder Method that has been added for Visual Studio 2017.

Notifies listening clients that the folder has been opened.

public void OnAfterOpenFolder (string folderPath);

Since this is a native COM interface, you also have to make sure the implementing class is COM visible (through the ComVisible attribute that you can set on the assembly, on the class, on a base class, etc.).

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298