Skip to content

Instantly share code, notes, and snippets.

@mikeminutillo
Created June 12, 2015 01:25
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mikeminutillo/ef5011b8b0949763866d to your computer and use it in GitHub Desktop.
Save mikeminutillo/ef5011b8b0949763866d to your computer and use it in GitHub Desktop.
Get project dependency graph out using yuml.me and LINQPad
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