Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 896
RichieHindle Avatar asked Sep 24 '17 13:09

RichieHindle


People also ask

How do I open the solution folder in Visual Studio?

In Visual Studio, click File > Open > Folder. Navigate to the folder, and click Select Folder. This opens the folder in Solution Explorer and displays its contents, files and any subfolders.

How do I open a folder in Visual Studio using CMD?

The first requirement is to be able to start Visual Studio from the command line. The equivalent of the “code” command is “devenv”. If you type this in your command line Visual Studio opens. Just ensure that the command is included in your path if you use a normal command prompt.

How do I open two projects in Visual Studio?

Open a second instance of Visual Studio for Mac To open a second instance of the integrated development environment (IDE), right-click on the Visual Studio icon in your dock or Applications folder, and select New Instance.


1 Answers

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

like image 160
Simon Mourier Avatar answered Oct 07 '22 22:10

Simon Mourier