VS2010 DTE插件:解决方案文件夹中的项目不是“ Project”, [英] VS2010 DTE Addin: project inside solution folder is not "Project"

查看:184
本文介绍了VS2010 DTE插件:解决方案文件夹中的项目不是“ Project”,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小vs插件,它可以在解决方案中查找项目并对其进行一些处理。我收集这样的项目:

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>();

但是,一旦我引入了solution文件夹并在其中放置了一个项目,那个项目突然无处可寻。因此,我尝试了

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


  • 项目上调用 item是Project 解决方案内部为 TRUE

  • 直接在解决方案内部为 TRUE (小wtf)

  • 解决方案文件夹中的
  • 项目(我在 folder.ProjectItems 中找到了它)错误! (当然,显式强制转换会引发错误)

  • 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)

到底是什么?
不强制转换到 Project ,我无法调用 FullName Properties()及其上的许多其他内容,即使我强制使用 dynamic

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!

推荐答案

答案在这里: http://www.wwwlicious.com/2011/03/29/envdte-getting-all-projects-html/

只需几处更改:

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

这篇关于VS2010 DTE插件:解决方案文件夹中的项目不是“ Project”,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆