Created
February 9, 2017 04:18
-
-
Save lindexi/3105bd0f0c5225bec4aa476f84dd29db to your computer and use it in GitHub Desktop.
获取 dte 所有项目
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static int TryParseProject(DTE dte, List<string> project) | |
{ | |
int noLoadProjectCount = 0; | |
foreach (var temp in dte.Solution.Projects) | |
{ | |
try | |
{ | |
if (temp is Project) | |
{ | |
if (((Project) temp).Kind == ProjectKinds.vsProjectKindSolutionFolder) | |
{ | |
project.AddRange(GetSolutionFolderProjects((Project) temp).Select(ParseProjectFolder)); | |
} | |
else | |
{ | |
project.Add(ParseProjectFolder((Project)temp)); | |
} | |
} | |
} | |
catch (NotImplementedException) | |
{ | |
noLoadProjectCount++; | |
} | |
} | |
return noLoadProjectCount; | |
} | |
private static string ParseProjectFolder(Project project) | |
{ | |
var file = project.FullName; | |
if (!string.IsNullOrEmpty(file)) | |
{ | |
return new FileInfo(file).Directory?.FullName; | |
} | |
return ""; | |
} | |
private static List<Project> GetSolutionFolderProjects(Project solutionFolder) | |
{ | |
List<Project> project = new List<Project>(); | |
for (var i = 1; i <= solutionFolder.ProjectItems.Count; i++) | |
{ | |
var subProject = solutionFolder.ProjectItems.Item(i).SubProject; | |
if (subProject == null) | |
{ | |
continue; | |
} | |
// If this is another solution folder, do a recursive call, otherwise add | |
if (subProject.Kind == ProjectKinds.vsProjectKindSolutionFolder) | |
{ | |
project.AddRange(GetSolutionFolderProjects(subProject)); | |
} | |
else | |
{ | |
project.Add(subProject); | |
} | |
} | |
return project; | |
} | |
http://lindexi.oschina.io/lindexi/post/VisualStudio-%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment