简体   繁体   English

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

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

Just trying to get up to speed with the SDK... 只是想加快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? 任何线索?

Check this code by Microsoft : 请查看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.

相关问题 如何将Java解决方案组织到多个项目中,例如在Visual Studio中? - How do you organise a Java solution into multiple projects, like in Visual Studio? 在 VSIX Visual Studio 扩展性中,如何获取函数的参数是“ref”、“out”还是值类型 - In VSIX Visual Studio Extensibility How do you get whether a Parameter of a Function is an 'ref', 'out' or value type 解决方案中的Visual Studio 2017可扩展性项目计数 - Visual Studio 2017 Extensibility Project count in Solution Visual Studio可扩展性 - Visual Studio extensibility 如何在Visual Studio 2012中切换(或突出显示)同一解决方案的项目? - How do i switch between (or highlight) projects of the same solution in Visual Studio 2012? Visual Studio 解决方案资源管理器未在解决方案中显示项目 - Visual Studio Solution Explorer not showing projects in solution 如何获取当前Visual Studio解决方案中的项目列表? - How to get list of projects in current Visual studio solution? Visual Studio 2010:如何在解决方案中强制执行项目的构建顺序? - Visual Studio 2010: How to enforce build order of projects in a solution? 如何构建和部署具有多个项目的Visual Studio解决方案 - How to build and deploy a visual studio solution with multiple projects 如何使用开源依赖项组织开源Visual Studio项目? - How do you organise open-source Visual Studio projects with open-source dependencies?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM