views:

278

answers:

1

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?

+5  A: 

Check this code by Microsoft:

    static public IEnumerable<IVsProject> LoadedProjects
    {
        get
        {
            IVsSolution solution = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
            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];
            }
        }
    }
eed3si9n