How to get folders under projects?

非 Y 不嫁゛ 提交于 2019-12-01 08:21:41

You could use EnvDTE.Constants.vsProjectItemKindPhysicalFolder to compare the ProjectItem.Kind property against.

More constants can be found here: http://msdn.microsoft.com/library/vstudio/envdte.constants

You can use ProjectKinds.vsProjectKindSolutionFolder to see whether the Project is a Folder or not.

e.g.

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;
     if (itemType  == ProjectKinds.vsProjectKindSolutionFolder)
     {
         // Do whatever
     }
  }
}

EDIT: As mentioned in my comment, I realised after posting that the above is for SolutionFolders which are a Project.Kind rather than a ProjectItem.Kind. Regarding the GUIDS, Microsoft say:

The Kind property of Project or ProjectItem does not return an enum value (since .NET must accommodate project kinds provided by 3rd parties). So, the Kind property returns a unique GUID string to identity the kind. The extensibility model provides some of these GUIDs scattered through several assemblies and classes (EnvDTE.Constants, VSLangProj.PrjKind, VSLangProj2.PrjKind2, etc.) but sometimes you will have to guess the values and hardcode them.

From http://support.microsoft.com/kb/555561. As I said in the comment, hopefully the GUID for a ProjectItem of Kind "Folder" is the same across the board. You just need to determine this GUID and hardcode it.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!