Multi Project Validator
A tool which searches recursively for project.json files, runs a set of analyses and reports on the result. For CLI we have only one rule currently, that Dependencies between projects must be equivalent to avoid stomping.
This commit is contained in:
parent
b25c2743ca
commit
6ff7404a48
10 changed files with 404 additions and 1 deletions
41
tools/MultiProjectValidator/ProjectLoader.cs
Normal file
41
tools/MultiProjectValidator/ProjectLoader.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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<ProjectContext> 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<ProjectContext> LoadProjectContexts(string[] projectFiles)
|
||||
{
|
||||
var projectContexts = new List<ProjectContext>();
|
||||
|
||||
foreach (var file in projectFiles)
|
||||
{
|
||||
var fileTargetContexts = ProjectContext.CreateContextForEachTarget(file);
|
||||
|
||||
projectContexts.AddRange(fileTargetContexts);
|
||||
}
|
||||
|
||||
return projectContexts;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue