using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.DotNet.ProjectModel; namespace MultiProjectValidator { public class ProjectLoader { private static readonly string PROJECT_FILENAME = "project.json"; public static List Load(string rootPath, bool recursive=true) { var projectFiles = DiscoverProjectFiles(rootPath); var projectContextList = LoadProjectContexts(projectFiles); return projectContextList; } private static string[] DiscoverProjectFiles(string rootPath) { return Directory.GetFiles(rootPath, PROJECT_FILENAME, SearchOption.AllDirectories); } private static List LoadProjectContexts(string[] projectFiles) { var projectContexts = new List(); foreach (var file in projectFiles) { var fileTargetContexts = ProjectContext.CreateContextForEachTarget(file); projectContexts.AddRange(fileTargetContexts); } return projectContexts; } } }