2

I figured out how to load a .csproj file using the Microsoft.Build namespace and extract a couple of properties:

var projectCollection = new ProjectCollection();
projectCollection.LoadProject(@"C:\path\to\my.csproj");
string assemblyName = projectCollection.LoadedProjects.First().GetPropertyValue("AssemblyName");
string outputPath = projectCollection.LoadedProjects.First().GetPropertyValue("OutputPath");

Now how can I use Microsoft.Build to load a .sln file and get the list of .csproj files?

Mark Nugent
  • 599
  • 2
  • 5
  • 20
  • It would be better to [edit] your question and add the additional information there. It's not only easier for others to see, but it can be properly formatted for readability. – Ken White Jul 20 '16 at 03:14
  • Dupe to http://stackoverflow.com/questions/707107/parsing-visual-studio-solution-files – kurakura88 Jul 20 '16 at 03:29

1 Answers1

5

For parsing solution file you can use SolutionFile class:

var solutionFile = SolutionFile.Parse(@"SOLUTION_PATH.sln");
var projectNames = solutionFile.ProjectsInOrder.Select(p => p.ProjectName).ToList();
Aleksey L.
  • 35,047
  • 10
  • 74
  • 84