简体   繁体   中英

Get list of projects from Visual Studio .sln file using Microsoft.Build namespace

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?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM