Instantly share code, notes, and snippets.

Embed
What would you like to do?
获取 dte 所有项目
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