Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 308
Keith Nicholas Avatar asked Nov 20 '08 04:11

Keith Nicholas


1 Answers

Check this code by 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];
            }
        }
    }
like image 166
Eugene Yokota Avatar answered Sep 25 '22 01:09

Eugene Yokota