Created
June 12, 2015 01:25
-
-
Save mikeminutillo/ef5011b8b0949763866d to your computer and use it in GitHub Desktop.
Get project dependency graph out using yuml.me and LINQPad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var ignores = new Regex[] | |
{ | |
new Regex(@"Approval"), | |
new Regex(@"Test"), | |
new Regex(@"Demo") | |
}; | |
var serviceControl = @"C:\Code\Particular\ServiceControl\src\"; | |
Util.Image("http://yuml.me/diagram/scruffy;scale:150/class/" + String.Join(",", GetDependencies(serviceControl, ignores))).Dump(); | |
} | |
public static IEnumerable<string> GetDependencies(string path, Regex[] ignores) | |
{ | |
foreach(var proj in Directory.EnumerateFiles(path, "*.csproj", SearchOption.AllDirectories).Where(x => !ignores.Any(y => y.IsMatch(x)))) | |
foreach(var dependency in GetProjectDependencies(proj, ignores)) | |
yield return dependency; | |
} | |
public static IEnumerable<string> GetProjectDependencies(string pathToCsProj, params Regex[] ignore) | |
{ | |
var doc = XDocument.Load(pathToCsProj); | |
var ns = (XNamespace)"http://schemas.microsoft.com/developer/msbuild/2003"; | |
foreach(var dependency in doc.Descendants(ns + "ProjectReference").Select(x => x.Attribute("Include").Value)) | |
{ | |
if(ignore.Any(x => x.IsMatch(dependency))) | |
continue; | |
yield return string.Format ("[{0}]->[{1}]", Path.GetFileNameWithoutExtension(pathToCsProj), Path.GetFileNameWithoutExtension(dependency)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment