How can I get only projects from the solution?

2019-03-28 12:32发布

问题:

I get a list of projects using following:

var solution = (IVsSolution)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(IVsSolution));

Refer following link for more details.

But it gives me each and every item in the solution like Directories, projects, etc. I require only projects.

How can I get only projects from the solution?

回答1:

I tried and got the expected results. There may be other better solution but this actually works for me.

var projects = CommonMethods.GetProjects(solution).Where(item => item.FullName != string.Empty).ToList();


回答2:

Sry I'm just begining with programming so it could be that my solving way is really not the best but i faced the same problem short time ago.

To solve this problem I parsed all items of the solution in a list and later i just checked if the relativ path of the items has the suffix '.csproj' or any other kind of project i need and wrote them into a new list maybe this could help you to?