Skip to content

Commit

Permalink
Support for vcxproj and vbproj.....I think
Browse files Browse the repository at this point in the history
  • Loading branch information
PeteGoo committed May 26, 2014
1 parent 04e03e5 commit ea68c56
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
27 changes: 20 additions & 7 deletions ProjectDependencyVisualiser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ static void Main(string[] args)
throw new DirectoryNotFoundException(startingFolder);
}

var projectFiles = Directory.GetFiles(startingFolder, "*.csproj", SearchOption.AllDirectories);
var projectFiles = Directory.GetFiles(startingFolder, "*.csproj", SearchOption.AllDirectories)
.Concat(Directory.GetFiles(startingFolder, "*.vbproj", SearchOption.AllDirectories))
.Concat(Directory.GetFiles(startingFolder, "*.vcxproj", SearchOption.AllDirectories));

var excludeFilters = (arguments.ExcludeFilters ?? string.Empty).Split(',').Select(x => x.Trim()).Where(x => !string.IsNullOrEmpty(x)).ToArray();
var includeFilters = (arguments.IncludeFilters ?? string.Empty).Split(',').Select(x => x.Trim()).Where(x => !string.IsNullOrEmpty(x)).ToArray();
Expand All @@ -58,16 +60,21 @@ static void Main(string[] args)
let xdoc = XDocument.Load(projectFilePath)
let idElement = xdoc.Descendants(XName.Get("ProjectGuid", MsBuildNamespace)).FirstOrDefault()
let nameElement = xdoc.Descendants(XName.Get("AssemblyName", MsBuildNamespace)).FirstOrDefault()
where idElement != null && nameElement != null
where idElement != null
select new
{
ProjectId = idElement.Value,
Name = nameElement.Value,
Name = nameElement == null ? Path.GetFileNameWithoutExtension(projectFilePath) : nameElement.Value,
References = GetProjectReferences(xdoc).ToArray()
}).ToArray();

foreach (var blankRef in references.SelectMany(r => r.References).Where(r => string.IsNullOrEmpty(r.Name)))
{
blankRef.Name = references.Where(r => r.ProjectId == blankRef.Identifier).Select(r => r.Name).FirstOrDefault();
}

var allProjects = references.Select(r => r.Name)
.Concat(references.SelectMany(r => r.References)).Distinct().OrderBy(r => r).ToArray();
.Concat(references.SelectMany(r => r.References).Where(r => r.Name != null).Select(r => r.Name)).Distinct().OrderBy(r => r).ToArray();

var dgmlNs = "http://schemas.microsoft.com/vs/2009/dgml";

Expand All @@ -91,19 +98,25 @@ select new
from reference in project.References
select new XElement(XName.Get("Link", dgmlNs),
new XAttribute("Source", Array.IndexOf(allProjects, project.Name)),
new XAttribute("Target", Array.IndexOf(allProjects, reference))));
new XAttribute("Target", Array.IndexOf(allProjects, reference.Name))));

outputXml.Save(arguments.OutputFile);

}

private static IEnumerable<string> GetProjectReferences(XDocument projectFileDocument)
private static IEnumerable<ProjectIdentity> GetProjectReferences(XDocument projectFileDocument)
{
return
from projectReference in
projectFileDocument.Descendants(XName.Get("ProjectReference", MsBuildNamespace))
let idElement = projectReference.Element(XName.Get("Project", MsBuildNamespace))
let nameElement = projectReference.Element(XName.Get("Name", MsBuildNamespace))
select nameElement.Value;
where idElement != null
select new ProjectIdentity(
idElement.Value,
nameElement == null
? Path.GetFileNameWithoutExtension(projectReference.Attribute("Include") .Value)
: nameElement.Value);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="ProjectIdentity.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TheArgs.cs" />
</ItemGroup>
Expand Down
35 changes: 35 additions & 0 deletions ProjectDependencyVisualiser/ProjectIdentity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace ProjectDependencyVisualiser
{
public class ProjectIdentity
{
protected bool Equals(ProjectIdentity other)
{
return string.Equals(Identifier, other.Identifier) && string.Equals(Name, other.Name);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((ProjectIdentity) obj);
}

public override int GetHashCode()
{
unchecked
{
return ((Identifier != null ? Identifier.GetHashCode() : 0)*397) ^ (Name != null ? Name.GetHashCode() : 0);
}
}

public string Identifier { get; private set; }
public string Name { get; set; }

public ProjectIdentity(string identifier, string name)
{
Identifier = identifier;
Name = name;
}
}
}

0 comments on commit ea68c56

Please sign in to comment.