2017年Visual Studio项目确定工作模式

Determination of the work mode with the project in Visual Studio 2017

2017 年 Visual Studio 可以在“文件夹视图”模式下工作。这是打开文件夹时运行的模式(文件 – 打开 – 文件夹...)。您也可以使用 'Solution Explorer' 切换到它(从 'Solution View' 切换到 'Folder View')。

是否可以通过编程方式确定(如果可以,那么如何确定)当前启用的模式?

我看到了 IVsSolutionEvents7 界面,其中包含调用的方法,例如,在打开或关闭文件夹时(文件 - 打开 - 文件夹/关闭文件夹),但没有找到任何有用的方法在解决上述问题时。

在此先感谢您的帮助。

您可以在 IVsSolution 参考上使用 __VSPROPID7.VSPROPID_IsInOpenFolderMode,代码如下:

var solution = (IVsSolution)ServiceProvider.GetService(typeof(SVsSolution));

// __VSPROPID7 needs Microsoft.VisualStudio.Shell.Interop.15.0.DesignTime.dll nuget
// folderMode will be a boolean
solution.GetProperty((int)__VSPROPID7.VSPROPID_IsInOpenFolderMode, out object folderMode);