Visual Studio的可扩展性,你如何枚举的解决方案的项目? [英] Visual Studio Extensibility, How do you enumerate the projects in a solution?

查看:180
本文介绍了Visual Studio的可扩展性,你如何枚举的解决方案的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想起床的SDK ...

Just trying to get up to speed with the SDK...

所以,我创建了自己的工具窗口....

So, I've created my own tool window....

现在我想通过在当前加载的解决方案的现有项目进行迭代,并在工具窗口中显示他们的名字......

Now I want to iterate through the existing projects in the currently loaded solution and display their names in the tool window....

不过不太清楚什么是最好的方式来枚举项目?任何线索?

but not quite sure what the best way to enumerate the projects? any clues?

推荐答案

勾选此的微软代码:

    static public IEnumerable<IVsProject> LoadedProjects
    {
        get
        {
            var solution = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
            if (solution == null)
            {
                Debug.Fail("Failed to get SVsSolution service.");
                yield break;
            }

            IEnumHierarchies enumerator = null;
            Guid guid = Guid.Empty;
            solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref guid, out enumerator);
            IVsHierarchy[] hierarchy = new IVsHierarchy[1] { null };
            uint fetched = 0;
            for (enumerator.Reset(); enumerator.Next(1, hierarchy, out fetched) == VSConstants.S_OK && fetched == 1; /*nothing*/)
            {
                yield return (IVsProject)hierarchy[0];
            }
        }
    }

这篇关于Visual Studio的可扩展性,你如何枚举的解决方案的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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