Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Add support for showing the full file path of projects #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 45 additions & 11 deletions MsBuildProjectReferenceDependencyGraph/MSBPRDependencyGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,34 @@ internal static string CreateDOTGraph(IDictionary<string, IEnumerable<string>> p
IEnumerable<KeyValuePair<string, IEnumerable<string>>> projectReferenceDependenciesToPrint = projectReferenceDependencies;
if (options.SortProjects)
{
projectReferenceDependenciesToPrint = projectReferenceDependencies.OrderBy(kvp => Path.GetFileName(kvp.Key));
projectReferenceDependenciesToPrint =
projectReferenceDependencies
.OrderBy
(
kvp =>
{
if (options.ShowFullPath)
{
return kvp.Key;
}
else
{
return Path.GetFileName(kvp.Key);
}
}
);
}

// Perform the ProjectReference Results
foreach (KeyValuePair<string, IEnumerable<string>> kvp in projectReferenceDependenciesToPrint)
{
string projectName = Path.GetFileName(kvp.Key);
// By Default show the full path to the project file
string projectName = kvp.Key;

if (!options.ShowFullPath)
{
projectName = Path.GetFileName(kvp.Key);
}

if (options.AnonymizeNames)
{
Expand All @@ -102,14 +123,19 @@ internal static string CreateDOTGraph(IDictionary<string, IEnumerable<string>> p

if (options.SortProjects)
{
projectReferences = projectReferences.OrderBy(filePath => Path.GetFileName(filePath));
projectReferences = projectReferences.OrderBy(filePath => filePath);
}

sb.AppendLine($"\"{projectName}\"");

foreach (string projectDependency in projectReferences)
{
string projectDependencyName = Path.GetFileName(projectDependency);
string projectDependencyName = projectDependency;

if (!options.ShowFullPath)
{
projectDependencyName = Path.GetFileName(projectDependencyName);
}

if (options.AnonymizeNames)
{
Expand All @@ -127,7 +153,7 @@ internal static string CreateDOTGraph(IDictionary<string, IEnumerable<string>> p
sb.AppendLine("// AssemblyReference Section");
sb.AppendLine("//--------------------------");
Dictionary<string, IEnumerable<string>> assemblyReferenceDependencies = ResolveAssemblyReferenceDependencies(projectReferenceDependencies.Keys);
IEnumerable<string> assemblyReferenceSection = GenerateAssemblyReferenceSection(anonymizer, assemblyReferenceDependencies);
IEnumerable<string> assemblyReferenceSection = GenerateAssemblyReferenceSection(anonymizer, options, assemblyReferenceDependencies);

if (options.SortProjects)
{
Expand All @@ -140,13 +166,13 @@ internal static string CreateDOTGraph(IDictionary<string, IEnumerable<string>> p
}
}

if(options.ShowPackageReferences)
if (options.ShowPackageReferences)
{
sb.AppendLine("//--------------------------");
sb.AppendLine("// PackageReference Section");
sb.AppendLine("//--------------------------");
Dictionary<string, IEnumerable<string>> packageReferenceDependencies = ResolvePackageReferenceDependencies(projectReferenceDependencies.Keys);
IEnumerable<string> packageReferenceSection = GeneratePackageReferenceSection(anonymizer, packageReferenceDependencies);
IEnumerable<string> packageReferenceSection = GeneratePackageReferenceSection(anonymizer, options, packageReferenceDependencies);

if (options.SortProjects)
{
Expand All @@ -170,7 +196,7 @@ internal static string CreateDOTGraph(IDictionary<string, IEnumerable<string>> p
/// <param name="anonymizer">The Anonymizer (if used) to anonymize names</param>
/// <param name="assemblyReferences">The Dictionary from <see cref="ResolveAssemblyReferenceDependencies(IEnumerable{string})"/></param>
/// <returns>An <see cref="IEnumerable{T}"/> that contains the lines to add to the DOT Graph</returns>
internal static IEnumerable<string> GenerateAssemblyReferenceSection(Anonymizer<string> anonymizer, Dictionary<string, IEnumerable<string>> assemblyReferences)
internal static IEnumerable<string> GenerateAssemblyReferenceSection(Anonymizer<string> anonymizer, MSBPROptions options, Dictionary<string, IEnumerable<string>> assemblyReferences)
{
// First we need to create nodes for each of the Assemblies
IEnumerable<string> distinctAssemblyReferences = assemblyReferences.SelectMany(kvp => kvp.Value).Distinct();
Expand All @@ -189,7 +215,11 @@ internal static IEnumerable<string> GenerateAssemblyReferenceSection(Anonymizer<
// Now Create the Connections
foreach (KeyValuePair<string, IEnumerable<string>> kvp in assemblyReferences)
{
string projectName = Path.GetFileName(kvp.Key);
string projectName = kvp.Key;
if (!options.ShowFullPath)
{
projectName = Path.GetFileName(kvp.Key);
}

if (anonymizer != null)
{
Expand Down Expand Up @@ -218,7 +248,7 @@ internal static IEnumerable<string> GenerateAssemblyReferenceSection(Anonymizer<
/// <param name="anonymizer">The Anonymizer (if used) to anonymize names</param>
/// <param name="packageReferences">The Dictionary from <see cref="ResolvePackageReferenceDependencies(IEnumerable{string})"/></param>
/// <returns>An <see cref="IEnumerable{T}"/> that contains the lines to add to the DOT Graph</returns>
internal static IEnumerable<string> GeneratePackageReferenceSection(Anonymizer<string> anonymizer, Dictionary<string, IEnumerable<string>> packageReferences)
internal static IEnumerable<string> GeneratePackageReferenceSection(Anonymizer<string> anonymizer, MSBPROptions options, Dictionary<string, IEnumerable<string>> packageReferences)
{
// First we need to create the nodes for each of the Packages
IEnumerable<string> distinctPackageReferences = packageReferences.SelectMany(kvp => kvp.Value).Distinct();
Expand All @@ -237,7 +267,11 @@ internal static IEnumerable<string> GeneratePackageReferenceSection(Anonymizer<s
// Now Create the Connections
foreach (KeyValuePair<string, IEnumerable<string>> kvp in packageReferences)
{
string projectName = Path.GetFileName(kvp.Key);
string projectName = kvp.Key;
if (!options.ShowFullPath)
{
projectName = Path.GetFileName(kvp.Key);
}

if (anonymizer != null)
{
Expand Down
2 changes: 2 additions & 0 deletions MsBuildProjectReferenceDependencyGraph/MSBPROptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class MSBPROptions
/// </summary>
public bool ShowAssemblyReferences { get; set; }

public bool ShowFullPath { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to show PackageReferences
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions MsBuildProjectReferenceDependencyGraph/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static void Main(string[] args)
{ "a|anonymize", Strings.AnonymizeDescription, v => options.AnonymizeNames = v != null },
{ "sA|ShowAllReferences", Strings.ShowAllReferencesDescription, v => { if(v != null) { options.ShowAssemblyReferences = true; options.ShowPackageReferences = true; } } },
{ "sar|ShowAssemblyReferences", Strings.ShowAssemblyReferencesDescription, v => options.ShowAssemblyReferences = v != null },
{ "sfp|ShowFullPath", Strings.ShowFullPathDescription, v=> options.ShowFullPath = v != null },
{ "spr|ShowPackageReferences", Strings.ShowPackageReferencesDescription, v => options.ShowPackageReferences = v != null },
{ "s|sort", Strings.SortDescription, v => options.SortProjects = v != null },
{ "?|h|help", Strings.HelpDescription, v => showHelp = v != null },
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ a DOT Graph of all its ProjectReference Elements.</value>
<data name="ShowAssemblyReferencesDescription" xml:space="preserve">
<value>Show "Assembly" References in graph</value>
</data>
<data name="ShowFullPathDescription" xml:space="preserve">
<value>Show the Full Path to the Project File</value>
</data>
<data name="ShowPackageReferencesDescription" xml:space="preserve">
<value>Show "PackageReference" References in graph</value>
</data>
Expand Down