Visual Studio 扩展 - 如何在 SolutionFolder 中创建 SolutionFolder?
Visual Studio Extensions - How to create a SolutionFolder inside a SolutionFolder?
据我所知here无法在 SolutionFolder 中添加 SolutionFolder:
Visual Studio 2005 and higher allows you to add folders to the
solution (which are called solution folders), not only to add folders
to a project (something that was already allowed by Visual Studio .NET
2002). Solution folders can be nested, and a folder that belongs to
the solution (a root solution folder) is modeled as an EnvDTE.Project,
so to add a child solution folder to a root solution folder you have
to use the EnvDTE.Project.ProjectItems.AddFolder method. However, this
method causes a NotImplementedException.
我现在正在尝试做同样的事情 - 在撰写该博文 7 年后,在 Visual Studio 2017 版本 15.8.4 - 不幸的是,我在尝试此操作时得到了相同的 NotImplementedException。
是否有任何其他可能的方法从 Visual Studio 扩展创建这样的子解决方案文件夹?
Visual Studio Extensions - How to create a SolutionFolder inside a SolutionFolder?
这里是关于如何从选定文件夹创建解决方案文件夹的扩展,还包括该选定文件夹中的文件:Folder To Solution Folder。
Remove the hassle of adding several files to solution folder. Just use
the context menu for the solution and just below the option of
creating a new solution folder you now find 'Add Folder as Solution
Folder'. This will create a solution folder with the same name as you
selected and add the items inside of that folder to the solution
folder. This will not move the files on disk.
您可以从以下位置查看源代码:https://github.com/ceciliasharp/Extension.FolderToSolutionFolder
希望对您有所帮助。
所以,看起来诀窍是获取要在其中创建子文件夹的 SolutionFolder 作为 EnvDTE.Project,然后获取其 Object 属性 并将其转换为 SolutionFolder.
这将为您提供一个对象,您可以在该对象上使用文件夹名称调用 "AddSolutionFolder"。
using EnvDTE;
using EnvDTE80;
Solution2 solution = (Solution2)dte.Solution;
// Adds a SolutionFolder (in the standard way) underneath the Solution and returns
// a Project. That Project object is the same as what you would get when going
// over your solution with solution.Projects and getting the folder you need
Project solutionFolderAsProject = solution.AddSolutionFolder(folder.Name);
SolutionFolder solutionFolderAsSolutionFolder = (SolutionFolder)solutionFolderAsProject.Object;
Project subSolutionFolder = solutionFolderAsSolutionFolder.AddSolutionFolder(item.Name);
据我所知here无法在 SolutionFolder 中添加 SolutionFolder:
Visual Studio 2005 and higher allows you to add folders to the solution (which are called solution folders), not only to add folders to a project (something that was already allowed by Visual Studio .NET 2002). Solution folders can be nested, and a folder that belongs to the solution (a root solution folder) is modeled as an EnvDTE.Project, so to add a child solution folder to a root solution folder you have to use the EnvDTE.Project.ProjectItems.AddFolder method. However, this method causes a NotImplementedException.
我现在正在尝试做同样的事情 - 在撰写该博文 7 年后,在 Visual Studio 2017 版本 15.8.4 - 不幸的是,我在尝试此操作时得到了相同的 NotImplementedException。
是否有任何其他可能的方法从 Visual Studio 扩展创建这样的子解决方案文件夹?
Visual Studio Extensions - How to create a SolutionFolder inside a SolutionFolder?
这里是关于如何从选定文件夹创建解决方案文件夹的扩展,还包括该选定文件夹中的文件:Folder To Solution Folder。
Remove the hassle of adding several files to solution folder. Just use the context menu for the solution and just below the option of creating a new solution folder you now find 'Add Folder as Solution Folder'. This will create a solution folder with the same name as you selected and add the items inside of that folder to the solution folder. This will not move the files on disk.
您可以从以下位置查看源代码:https://github.com/ceciliasharp/Extension.FolderToSolutionFolder
希望对您有所帮助。
所以,看起来诀窍是获取要在其中创建子文件夹的 SolutionFolder 作为 EnvDTE.Project,然后获取其 Object 属性 并将其转换为 SolutionFolder.
这将为您提供一个对象,您可以在该对象上使用文件夹名称调用 "AddSolutionFolder"。
using EnvDTE;
using EnvDTE80;
Solution2 solution = (Solution2)dte.Solution;
// Adds a SolutionFolder (in the standard way) underneath the Solution and returns
// a Project. That Project object is the same as what you would get when going
// over your solution with solution.Projects and getting the folder you need
Project solutionFolderAsProject = solution.AddSolutionFolder(folder.Name);
SolutionFolder solutionFolderAsSolutionFolder = (SolutionFolder)solutionFolderAsProject.Object;
Project subSolutionFolder = solutionFolderAsSolutionFolder.AddSolutionFolder(item.Name);