Forked from mikeminutillo/ProjectDependencies.cs
Last active
August 29, 2015 14:22
-
-
Save alimbada/ffa8b9d374c7598cb3a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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