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?

4
  • Are you looking for IVsSolutionEvents7::OnAfterOpenFolder? learn.microsoft.com/en-us/dotnet/api/… Commented Sep 24, 2017 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...? Commented Sep 24, 2017 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. Commented Sep 25, 2017 at 5: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). Commented Sep 25, 2017 at 22:31

1 Answer 1

6
+500

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.).

3
  • Wonderful - many thanks! I have a followup question here: stackoverflow.com/questions/46432488 on which I'd very much value your input. Commented Sep 26, 2017 at 17:30
  • @SimonMourier Do you know how to track the switch over 'Solution View' and 'Folder View' in Solution Explorer? May be there is an interface with the according methods? Commented Feb 28, 2018 at 7:47
  • @Nightwalker - you should ask another question Commented Feb 28, 2018 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.