From 720a20235bd8041f5bf43cfc857ddd1cb7dc1852 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Thu, 25 Apr 2019 20:55:51 -0400 Subject: [PATCH] fix issues with AllProjects not working with solution folders --- .../BridgeVsExtension.cs | 64 +++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/Src/BridgeVs.AsyncVsPackage/BridgeVsExtension.cs b/Src/BridgeVs.AsyncVsPackage/BridgeVsExtension.cs index 4357cb6..ecc7278 100644 --- a/Src/BridgeVs.AsyncVsPackage/BridgeVsExtension.cs +++ b/Src/BridgeVs.AsyncVsPackage/BridgeVsExtension.cs @@ -26,12 +26,14 @@ using System; using System.Collections.Generic; using System.ComponentModel.Design; +using System.Diagnostics; using System.IO; using System.Linq; using BridgeVs.VsPackage.Helper; using BridgeVs.VsPackage.Helper.Command; using BridgeVs.VsPackage.Helper.Configuration; using EnvDTE; +using Microsoft.VisualStudio; using Project = EnvDTE.Project; namespace BridgeVs.VisualStudio.AsyncExtension @@ -55,17 +57,71 @@ private IEnumerable AllProjects { get { + List projects = new List();//AllProjects.ToList(); + foreach (Project proj in _application.Solution.Projects) + { + _findProjects(projects, proj); + } Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); - Projects projects = _application.Solution.Projects; - if (projects == null) + if (projects.Count == 0) return Enumerable.Empty(); return from project in projects.Cast() - where IsSupported(project.UniqueName) + where (IsSupported(project.UniqueName) || IsSupported(project.FullName)) select project; } } - + + IEnumerable _findProjects(IList projects, Object projectItem) + { + var proj = projectItem as Project; + var projItm = projectItem as ProjectItem; + if (proj != null) + { + Debug.WriteLine($"Project => {proj.Name} {proj.Kind}"); + } + + if (projItm != null) + { + Debug.WriteLine($"ProjectItem => {projItm.Name} {projItm.Kind}"); + } + if (proj == null && projItm != null) + { + proj = projItm.SubProject; + } + if (proj != null) + { + Debug.WriteLine($"Resolved Project => {proj.Name} {proj.Kind}"); + } + if (proj != null && (proj.Kind == VSConstants.UICONTEXT.CSharpProject_string + || proj.Kind == VSConstants.UICONTEXT.VBProject_string + || IsSupported(proj.UniqueName))) + { + projects.Add(proj); + return projects; + } + else if (proj != null && (proj.Kind == VSConstants.ItemTypeGuid.VirtualFolder_string + || proj.Kind == "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}") + ) + { + foreach (ProjectItem itm in proj.ProjectItems) + { + _findProjects(projects, itm); + } + + return projects; + } + else if (proj == null && projItm != null && projItm.ProjectItems != null) + { + foreach (ProjectItem pi in projItm.ProjectItems) + { + _findProjects(projects, pi); + } + } + + return projects; + } + private string SolutionName => Path.GetFileNameWithoutExtension(_application.Solution.FileName); public void Execute(CommandAction action)