From 0b90853df0c7575a0b40345f3c88c00826a87614 Mon Sep 17 00:00:00 2001 From: Ace Olszowka Date: Fri, 28 Aug 2020 13:53:49 -0600 Subject: [PATCH] Initial cut at adding support --- .../MSBPRDependencyGraph.cs | 56 +++++++++++++++---- .../MSBPROptions.cs | 2 + .../Program.cs | 1 + .../Properties/Strings.Designer.cs | 9 +++ .../Properties/Strings.resx | 3 + 5 files changed, 60 insertions(+), 11 deletions(-) diff --git a/MsBuildProjectReferenceDependencyGraph/MSBPRDependencyGraph.cs b/MsBuildProjectReferenceDependencyGraph/MSBPRDependencyGraph.cs index 0774091..a02b921 100644 --- a/MsBuildProjectReferenceDependencyGraph/MSBPRDependencyGraph.cs +++ b/MsBuildProjectReferenceDependencyGraph/MSBPRDependencyGraph.cs @@ -85,13 +85,34 @@ internal static string CreateDOTGraph(IDictionary> p IEnumerable>> 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> 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) { @@ -102,14 +123,19 @@ internal static string CreateDOTGraph(IDictionary> 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) { @@ -127,7 +153,7 @@ internal static string CreateDOTGraph(IDictionary> p sb.AppendLine("// AssemblyReference Section"); sb.AppendLine("//--------------------------"); Dictionary> assemblyReferenceDependencies = ResolveAssemblyReferenceDependencies(projectReferenceDependencies.Keys); - IEnumerable assemblyReferenceSection = GenerateAssemblyReferenceSection(anonymizer, assemblyReferenceDependencies); + IEnumerable assemblyReferenceSection = GenerateAssemblyReferenceSection(anonymizer, options, assemblyReferenceDependencies); if (options.SortProjects) { @@ -140,13 +166,13 @@ internal static string CreateDOTGraph(IDictionary> p } } - if(options.ShowPackageReferences) + if (options.ShowPackageReferences) { sb.AppendLine("//--------------------------"); sb.AppendLine("// PackageReference Section"); sb.AppendLine("//--------------------------"); Dictionary> packageReferenceDependencies = ResolvePackageReferenceDependencies(projectReferenceDependencies.Keys); - IEnumerable packageReferenceSection = GeneratePackageReferenceSection(anonymizer, packageReferenceDependencies); + IEnumerable packageReferenceSection = GeneratePackageReferenceSection(anonymizer, options, packageReferenceDependencies); if (options.SortProjects) { @@ -170,7 +196,7 @@ internal static string CreateDOTGraph(IDictionary> p /// The Anonymizer (if used) to anonymize names /// The Dictionary from /// An that contains the lines to add to the DOT Graph - internal static IEnumerable GenerateAssemblyReferenceSection(Anonymizer anonymizer, Dictionary> assemblyReferences) + internal static IEnumerable GenerateAssemblyReferenceSection(Anonymizer anonymizer, MSBPROptions options, Dictionary> assemblyReferences) { // First we need to create nodes for each of the Assemblies IEnumerable distinctAssemblyReferences = assemblyReferences.SelectMany(kvp => kvp.Value).Distinct(); @@ -189,7 +215,11 @@ internal static IEnumerable GenerateAssemblyReferenceSection(Anonymizer< // Now Create the Connections foreach (KeyValuePair> kvp in assemblyReferences) { - string projectName = Path.GetFileName(kvp.Key); + string projectName = kvp.Key; + if (!options.ShowFullPath) + { + projectName = Path.GetFileName(kvp.Key); + } if (anonymizer != null) { @@ -218,7 +248,7 @@ internal static IEnumerable GenerateAssemblyReferenceSection(Anonymizer< /// The Anonymizer (if used) to anonymize names /// The Dictionary from /// An that contains the lines to add to the DOT Graph - internal static IEnumerable GeneratePackageReferenceSection(Anonymizer anonymizer, Dictionary> packageReferences) + internal static IEnumerable GeneratePackageReferenceSection(Anonymizer anonymizer, MSBPROptions options, Dictionary> packageReferences) { // First we need to create the nodes for each of the Packages IEnumerable distinctPackageReferences = packageReferences.SelectMany(kvp => kvp.Value).Distinct(); @@ -237,7 +267,11 @@ internal static IEnumerable GeneratePackageReferenceSection(Anonymizer> kvp in packageReferences) { - string projectName = Path.GetFileName(kvp.Key); + string projectName = kvp.Key; + if (!options.ShowFullPath) + { + projectName = Path.GetFileName(kvp.Key); + } if (anonymizer != null) { diff --git a/MsBuildProjectReferenceDependencyGraph/MSBPROptions.cs b/MsBuildProjectReferenceDependencyGraph/MSBPROptions.cs index a6d390c..3f0c997 100644 --- a/MsBuildProjectReferenceDependencyGraph/MSBPROptions.cs +++ b/MsBuildProjectReferenceDependencyGraph/MSBPROptions.cs @@ -21,6 +21,8 @@ public class MSBPROptions /// public bool ShowAssemblyReferences { get; set; } + public bool ShowFullPath { get; set; } + /// /// Gets or sets a value indicating whether to show PackageReferences /// diff --git a/MsBuildProjectReferenceDependencyGraph/Program.cs b/MsBuildProjectReferenceDependencyGraph/Program.cs index 54e632e..664dfb3 100644 --- a/MsBuildProjectReferenceDependencyGraph/Program.cs +++ b/MsBuildProjectReferenceDependencyGraph/Program.cs @@ -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 }, diff --git a/MsBuildProjectReferenceDependencyGraph/Properties/Strings.Designer.cs b/MsBuildProjectReferenceDependencyGraph/Properties/Strings.Designer.cs index d8162b5..84a4448 100644 --- a/MsBuildProjectReferenceDependencyGraph/Properties/Strings.Designer.cs +++ b/MsBuildProjectReferenceDependencyGraph/Properties/Strings.Designer.cs @@ -133,6 +133,15 @@ internal static string ShowAssemblyReferencesDescription { } } + /// + /// Looks up a localized string similar to Show the Full Path to the Project File. + /// + internal static string ShowFullPathDescription { + get { + return ResourceManager.GetString("ShowFullPathDescription", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show "PackageReference" References in graph. /// diff --git a/MsBuildProjectReferenceDependencyGraph/Properties/Strings.resx b/MsBuildProjectReferenceDependencyGraph/Properties/Strings.resx index b618207..f950b44 100644 --- a/MsBuildProjectReferenceDependencyGraph/Properties/Strings.resx +++ b/MsBuildProjectReferenceDependencyGraph/Properties/Strings.resx @@ -143,6 +143,9 @@ a DOT Graph of all its ProjectReference Elements. Show "Assembly" References in graph + + Show the Full Path to the Project File + Show "PackageReference" References in graph