2015-12-16 02:09:08 +00:00
|
|
|
|
using System.IO;
|
2015-12-11 03:01:40 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Microsoft.DotNet.ProjectModel;
|
|
|
|
|
|
|
|
|
|
namespace MultiProjectValidator
|
|
|
|
|
{
|
|
|
|
|
public class ProjectLoader
|
|
|
|
|
{
|
2016-01-08 01:10:45 +00:00
|
|
|
|
private static readonly string s_projectFileName = "project.json";
|
2015-12-11 03:01:40 +00:00
|
|
|
|
|
|
|
|
|
public static List<ProjectContext> Load(string rootPath, bool recursive=true)
|
|
|
|
|
{
|
|
|
|
|
var projectFiles = DiscoverProjectFiles(rootPath);
|
|
|
|
|
var projectContextList = LoadProjectContexts(projectFiles);
|
|
|
|
|
|
|
|
|
|
return projectContextList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string[] DiscoverProjectFiles(string rootPath)
|
|
|
|
|
{
|
2016-01-08 01:10:45 +00:00
|
|
|
|
return Directory.GetFiles(rootPath, s_projectFileName, SearchOption.AllDirectories);
|
2015-12-11 03:01:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<ProjectContext> LoadProjectContexts(string[] projectFiles)
|
|
|
|
|
{
|
|
|
|
|
var projectContexts = new List<ProjectContext>();
|
|
|
|
|
|
|
|
|
|
foreach (var file in projectFiles)
|
|
|
|
|
{
|
|
|
|
|
var fileTargetContexts = ProjectContext.CreateContextForEachTarget(file);
|
|
|
|
|
|
2016-01-08 01:10:45 +00:00
|
|
|
|
projectContexts.AddRange(fileTargetContexts);
|
2015-12-11 03:01:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return projectContexts;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|