如何在项目下获取文件夹? [英] How to get folders under projects?
问题描述
我正在尝试获取其下的项目和文件夹的列表.我可以使用以下项目获得项目和项目:
I am trying to get a list of projects and folders under it. I am able to get the projects and project-items using:
DTE2 dte2;
dte2=(DTE2)System.Runtime.InteropServices.Marshal.
GetActiveObject("VisualStudio.DTE.10.0");
Projects projects = dte2.Solution.Projects;
然后,我遍历项目项并获取项的种类".但它只显示GUID.我需要知道该项目是否为文件夹.我该怎么办?
Then, I am iterating through the project items and getting the "kind" of item. But it is showing only GUID. I need to know whether the item is a Folder. How do I do that?
参考:
var item = projects.GetEnumerator();
while (item.MoveNext())
{
var project = item.Current as Project;
for(i=1;i<project.ProjectItems.Count;i++)
{
string itemType = project.ProjectItems.Item(i).Kind;
}
}
当前,我正在使用一种解决方法:
Currently, I am using a workaround:
string location = project.ProjectItems.Item(i).get_FileNames(1);
if (location.EndsWith(@"\"))
{
// It is a folder E.g C:\\Abc\\Xyz\\
}
推荐答案
您可以使用 EnvDTE.Constants.vsProjectItemKindPhysicalFolder
来比较 ProjectItem.Kind
属性.
You could use EnvDTE.Constants.vsProjectItemKindPhysicalFolder
to compare the ProjectItem.Kind
property against.
更多常量可以在这里找到: http://msdn.microsoft.com/library/vstudio/envdte.常数
More constants can be found here: http://msdn.microsoft.com/library/vstudio/envdte.constants
这篇关于如何在项目下获取文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!