繁体   English   中英

Visual Studio可扩展性,如何枚举解决方案中的项目?

[英]Visual Studio Extensibility, How do you enumerate the projects in a solution?

只是想加快SDK的速度......

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

现在我想迭代当前加载的解决方案中的现有项目,并在工具窗口中显示它们的名称....

但不太确定枚举项目的最佳方法是什么? 任何线索?

请查看Microsoft的代码

    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];
            }
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM