Search code examples
visual-studiovisual-studio-2017vsixvs-extensibility

In a Visual Studio Extension, how to respond to "Open Folder" as well as "Open Solution"?


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?


Solution

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