VS2010 DTE Addin: project inside solution folder is not “Project”

梦想与她 提交于 2019-12-10 13:30:28

问题


I have a small vs addin which looks for projects inside a solution and does a few stuff with it. I collect the projects like this:

Application.DTE.Solution.Projects.OfType<Project>();

However, as soon as I introduced a solution folder and placed a project inside it, suddenly that project was nowhere to be found. So, I've tried

 private IEnumerable<Project> getProjectsRecursive(IEnumerable<Project> iEnumerable)
 {
      foreach (var item in iEnumerable)
      {
          yield return item;
          foreach (var child in getProjectsRecursive(item.ProjectItems.OfType<Project>()))
          {
              yield return child;
          }
      }
 }
public IEnumerable<Project> EveryProject { get { return getProjectsRecursive(Application.DTE.Solution.Projects.OfType<Project>()); } }

still the project is not there. So I've checked manually, calling item is Project on a

  • project directly inside the solution is TRUE
  • solution folder directly inside the solution is TRUE (small wtf)
  • project inside a solution folder (I've found it in folder.ProjectItems) is FALSE !!!!! (and of course explicit casting throws an error)

What the hell? Without casting it to Project, I cannot call FullName, Properties() and many other things on it, even if I cast to dynamic. Please help!


回答1:


The answer is here : http://www.wwwlicious.com/2011/03/29/envdte-getting-all-projects-html/

Just few changes :

if (project.Kind == EnvDTE.Constants.vsProjectKindSolutionItems)


来源:https://stackoverflow.com/questions/6410911/vs2010-dte-addin-project-inside-solution-folder-is-not-project

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