├── .gitignore ├── Directory.Build.rsp ├── LICENSE ├── MSBuildGraph.sln ├── README.md ├── README.png └── src ├── GraphGen ├── Directory.Build.props ├── EnumerableExtensions.cs ├── GraphGen.csproj ├── GraphVis.cs ├── GraphVisCluster.cs ├── GraphVisEdge.cs ├── GraphVisNode.cs ├── Program.cs ├── SolutionParser.cs ├── app.config └── nuget.config └── MSBuildGraphUI ├── App.config ├── MSBuildGraphForm.Designer.cs ├── MSBuildGraphForm.cs ├── MSBuildGraphForm.resx ├── MSBuildGraphUI.csproj ├── Program.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings └── WG ├── WGEdge.cs ├── WGNode.cs └── WebGraph.cs /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /Directory.Build.rsp: -------------------------------------------------------------------------------- 1 | -ConsoleLoggerParameters:Verbosity=Minimal;Summary;ForceNoAlign 2 | -MaxCPUCount 3 | -NodeReuse:false 4 | -Restore 5 | -Property:RestoreUseStaticGraphEvaluation=true 6 | -Graph -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Andy Gerlicher 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MSBuildGraph.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28531.181 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSBuildGraphUI", "src\MSBuildGraphUI\MSBuildGraphUI.csproj", "{1C2C61EF-C498-406E-A33A-64E6158E6C93}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphGen", "src\GraphGen\GraphGen.csproj", "{8BAE078E-9ADD-477F-BFA2-59956452640F}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Release|Any CPU = Release|Any CPU 15 | Release|x64 = Release|x64 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {1C2C61EF-C498-406E-A33A-64E6158E6C93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {1C2C61EF-C498-406E-A33A-64E6158E6C93}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {1C2C61EF-C498-406E-A33A-64E6158E6C93}.Debug|x64.ActiveCfg = Debug|x64 21 | {1C2C61EF-C498-406E-A33A-64E6158E6C93}.Debug|x64.Build.0 = Debug|x64 22 | {1C2C61EF-C498-406E-A33A-64E6158E6C93}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {1C2C61EF-C498-406E-A33A-64E6158E6C93}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {1C2C61EF-C498-406E-A33A-64E6158E6C93}.Release|x64.ActiveCfg = Release|x64 25 | {1C2C61EF-C498-406E-A33A-64E6158E6C93}.Release|x64.Build.0 = Release|x64 26 | {AD8D7D5E-14DE-4B5E-9101-D7DE4A6E840E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {AD8D7D5E-14DE-4B5E-9101-D7DE4A6E840E}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {AD8D7D5E-14DE-4B5E-9101-D7DE4A6E840E}.Debug|x64.ActiveCfg = Debug|x64 29 | {AD8D7D5E-14DE-4B5E-9101-D7DE4A6E840E}.Debug|x64.Build.0 = Debug|x64 30 | {AD8D7D5E-14DE-4B5E-9101-D7DE4A6E840E}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {AD8D7D5E-14DE-4B5E-9101-D7DE4A6E840E}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {AD8D7D5E-14DE-4B5E-9101-D7DE4A6E840E}.Release|x64.ActiveCfg = Release|x64 33 | {AD8D7D5E-14DE-4B5E-9101-D7DE4A6E840E}.Release|x64.Build.0 = Release|x64 34 | {8BAE078E-9ADD-477F-BFA2-59956452640F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {8BAE078E-9ADD-477F-BFA2-59956452640F}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {8BAE078E-9ADD-477F-BFA2-59956452640F}.Debug|x64.ActiveCfg = Debug|Any CPU 37 | {8BAE078E-9ADD-477F-BFA2-59956452640F}.Debug|x64.Build.0 = Debug|Any CPU 38 | {8BAE078E-9ADD-477F-BFA2-59956452640F}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {8BAE078E-9ADD-477F-BFA2-59956452640F}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {8BAE078E-9ADD-477F-BFA2-59956452640F}.Release|x64.ActiveCfg = Release|Any CPU 41 | {8BAE078E-9ADD-477F-BFA2-59956452640F}.Release|x64.Build.0 = Release|Any CPU 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | GlobalSection(ExtensibilityGlobals) = postSolution 47 | SolutionGuid = {85EA7B35-83F0-47E7-99F6-5B8B36AF3CB4} 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MSBuildGraphUIVisualizer 2 | 3 | Run `msbuild` 4 | 5 | Run `src\MSBuildGraphUI\bin\Debug\MSBuildGraphUI.exe` 6 | 7 | Load a project and maybe the graph will load. Works on my machine. 8 | 9 | ![image](README.png) 10 | -------------------------------------------------------------------------------- /README.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndyGerlicher/MSBuildGraphVisualizer/cfb2a60c9ca1d5aff495dc8677cab1145f21757c/README.png -------------------------------------------------------------------------------- /src/GraphGen/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/GraphGen/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace GraphGen 9 | { 10 | public static class EnumerableExtensions 11 | { 12 | public static IEnumerable ToEnumerable(this IEnumerator enumerator) 13 | { 14 | while (enumerator.MoveNext()) 15 | { 16 | yield return enumerator.Current; 17 | } 18 | } 19 | 20 | public static IEnumerable ToEnumerable(this IEnumerator enumerator) 21 | { 22 | while (enumerator.MoveNext()) 23 | { 24 | yield return enumerator.Current; 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/GraphGen/GraphGen.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net472 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/GraphGen/GraphVis.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Security.Cryptography; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using GraphVizWrapper; 10 | using GraphVizWrapper.Commands; 11 | using GraphVizWrapper.Queries; 12 | using Microsoft.Build.Execution; 13 | using Microsoft.Build.Graph; 14 | 15 | namespace GraphGen 16 | { 17 | public class GraphVis 18 | { 19 | public static string Create(ConcurrentDictionary projects) 20 | { 21 | HashSet seen = new HashSet(); 22 | 23 | var sb = new StringBuilder(); 24 | var edges = new StringBuilder(); 25 | var nodes = new StringBuilder(); 26 | var clusters = new StringBuilder(); 27 | 28 | foreach (var group in projects 29 | .Where(n => !n.Value.ProjectInstance.FullPath.Contains("dirs.proj")) 30 | .GroupBy(kvp => kvp.Value.ProjectInstance.FullPath, (p, plist) => new { ProjectGroupName = p, Projects = projects.Where(p2=>p2.Value.ProjectInstance.FullPath == p).ToList()})) 31 | { 32 | GraphVisCluster cluster = new GraphVisCluster(group.ProjectGroupName); 33 | 34 | foreach (var node in group.Projects) 35 | { 36 | var graphNode = new GraphVisNode(node.Value); 37 | cluster.AddNode(graphNode); 38 | 39 | if (seen.Contains(node.Value)) continue; 40 | seen.Add(node.Value); 41 | 42 | nodes.AppendLine(graphNode.Create()); 43 | 44 | foreach (var subNode in node.Value.ProjectReferences) 45 | { 46 | var subGraphVisNode = new GraphVisNode(subNode); 47 | var edgeString = new GraphVisEdge(graphNode, subGraphVisNode); 48 | 49 | edges.AppendLine(edgeString.Create()); 50 | 51 | if (!seen.Contains(node.Value)) 52 | nodes.AppendLine(subGraphVisNode.Create()); 53 | } 54 | } 55 | 56 | clusters.AppendLine(cluster.Create()); 57 | } 58 | 59 | sb.AppendLine("digraph prof {"); 60 | sb.AppendLine(" ratio = fill;"); 61 | sb.AppendLine(" nodesep = .1;"); 62 | sb.AppendLine(" ranksep = 3.0;"); 63 | sb.AppendLine(" node [style=filled];"); 64 | sb.Append(clusters); 65 | sb.Append(edges); 66 | sb.AppendLine("}"); 67 | GraphVisNode._count = 1; 68 | return sb.ToString(); 69 | } 70 | 71 | public static void SaveAsPng(string graphText, string outFile) 72 | { 73 | // These three instances can be injected via the IGetStartProcessQuery, 74 | // IGetProcessStartInfoQuery and 75 | // IRegisterLayoutPluginCommand interfaces 76 | 77 | var getStartProcessQuery = new GetStartProcessQuery(); 78 | var getProcessStartInfoQuery = new GetProcessStartInfoQuery(); 79 | var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery); 80 | 81 | // GraphGeneration can be injected via the IGraphGeneration interface 82 | 83 | var wrapper = new GraphGeneration(getStartProcessQuery, 84 | getProcessStartInfoQuery, 85 | registerLayoutPluginCommand); 86 | 87 | byte[] output = wrapper.GenerateGraph(graphText, Enums.GraphReturnType.Png); 88 | File.WriteAllBytes(outFile, output); 89 | 90 | Console.WriteLine(); 91 | Console.WriteLine($"{output.Length} bytes written to {outFile}."); 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /src/GraphGen/GraphVisCluster.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | 4 | namespace GraphGen 5 | { 6 | public class GraphVisCluster 7 | { 8 | private static int _clusterIdGlobal = 0; 9 | private static int _clusterId; 10 | 11 | private readonly string _projectName; 12 | private readonly List _nodes = new List(); 13 | private readonly string _clusterLabel; 14 | 15 | public GraphVisCluster(string projectPath) 16 | { 17 | _projectName = Path.GetFileNameWithoutExtension(projectPath).Replace(".", string.Empty); 18 | _clusterLabel = Path.GetFileName(projectPath); 19 | _clusterId = _clusterIdGlobal; 20 | _clusterIdGlobal++; 21 | } 22 | 23 | public void AddNode(GraphVisNode node) 24 | { 25 | _nodes.Add(node); 26 | } 27 | 28 | public string Create() 29 | { 30 | if (_nodes.Count == 1) 31 | { 32 | return _nodes[0].Create(); 33 | } 34 | 35 | var result = $@" 36 | subgraph cluster_{_clusterId} {{ 37 | style=filled; 38 | color=lightgrey; 39 | node [style=filled,color=white]; 40 | label = ""{_clusterLabel}"";"; 41 | 42 | foreach (var p in _nodes) 43 | { 44 | result += p.Create(); 45 | } 46 | 47 | result += "}"; 48 | return result; 49 | 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/GraphGen/GraphVisEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Security.Cryptography.X509Certificates; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace GraphGen 10 | { 11 | public class GraphVisEdge 12 | { 13 | private readonly GraphVisNode _node1; 14 | private readonly GraphVisNode _node2; 15 | 16 | public GraphVisEdge(GraphVisNode node1, GraphVisNode node2) 17 | { 18 | _node1 = node1; 19 | _node2 = node2; 20 | } 21 | 22 | public string Create() 23 | { 24 | //var (n1, _) = GraphVisNode.GetNodeInfo(node); 25 | //var (n2, _) = GraphVisNode.GetNodeInfo(subNode); 26 | 27 | return $" {_node1.Name} -> {_node2.Name};"; //[color=\"0.002 0.999 0.999\"];"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/GraphGen/GraphVisNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using Microsoft.Build.Graph; 7 | 8 | namespace GraphGen 9 | { 10 | public class GraphVisNode 11 | { 12 | private readonly ProjectGraphNode _node; 13 | private readonly string _label; 14 | 15 | public string Name { get; } 16 | 17 | public GraphVisNode(ProjectGraphNode node) 18 | { 19 | _node = node; 20 | var (name, label) = GetNodeInfo(node); 21 | Name = name; 22 | _label = label; 23 | } 24 | 25 | internal string Create() 26 | { 27 | var globalPropertiesString = string.Join("\n", _node.ProjectInstance.GlobalProperties.OrderBy(kvp => kvp.Key).Where(kvp => kvp.Key != "IsGraphBuild").Select(kvp => $"{kvp.Key}={kvp.Value}")); 28 | if (globalPropertiesString.StartsWith("TargetFramework=")) 29 | { 30 | globalPropertiesString = globalPropertiesString.Substring("TargetFramework=".Length); 31 | } 32 | 33 | return $" {Name} [label=\"{_label}\n{globalPropertiesString}\", shape=box];"; //, color=\"0.650 0.200 1.000\"];"; 34 | } 35 | 36 | private static Dictionary _nodes = new Dictionary(); 37 | public static int _count = 1; 38 | 39 | private static (string, string) GetNodeInfo(ProjectGraphNode node) 40 | { 41 | var label = Path.GetFileNameWithoutExtension(node.ProjectInstance.FullPath); 42 | if (!_nodes.ContainsKey(node)) 43 | { 44 | _nodes.Add(node, label.Replace(".", string.Empty) + _count); 45 | _count++; 46 | } 47 | var name = _nodes[node]; 48 | //var name = _current;//label + Program.HashGlobalProps(node.ProjectInstance.GlobalProperties); 49 | 50 | return (name, label); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/GraphGen/Program.cs: -------------------------------------------------------------------------------- 1 | using GraphVizWrapper; 2 | using GraphVizWrapper.Commands; 3 | using GraphVizWrapper.Queries; 4 | using Microsoft.Build.Evaluation; 5 | using Microsoft.Build.Locator; 6 | using System; 7 | using System.Collections.Concurrent; 8 | using System.Collections.Generic; 9 | using System.Diagnostics; 10 | using System.IO; 11 | using System.Security.Cryptography; 12 | using System.Text; 13 | using Microsoft.Build.Graph; 14 | 15 | namespace GraphGen 16 | { 17 | class Program 18 | { 19 | static void Main(string[] args) 20 | { 21 | var msbuildpath = args[0]; 22 | var projectFile = args[1]; 23 | var outFile = args.Length > 2 ? args[2] : "out.png"; 24 | 25 | MSBuildLocator.RegisterMSBuildPath(msbuildpath); 26 | 27 | var graphText = new Program().LoadGraph(projectFile); 28 | GraphVis.SaveAsPng(graphText, outFile); 29 | } 30 | 31 | private string LoadGraph(string file) 32 | { 33 | Console.WriteLine("Loading graph..."); 34 | var sw = Stopwatch.StartNew(); 35 | var graph = new ProjectGraph(file, ProjectCollection.GlobalProjectCollection); //, ProjectInstanceFactory) 36 | Console.WriteLine($@"{file} loaded {graph.ProjectNodes.Count} node(s) in {sw.ElapsedMilliseconds}ms."); 37 | 38 | var projects = new ConcurrentDictionary(); 39 | 40 | foreach (var item in graph.ProjectNodes) 41 | { 42 | var propsHash = HashGlobalProps(item.ProjectInstance.GlobalProperties); 43 | projects.TryAdd(item.ProjectInstance.FullPath + propsHash, item); 44 | } 45 | 46 | return GraphVis.Create(projects); 47 | } 48 | 49 | private const char ItemSeparatorCharacter = '\u2028'; 50 | 51 | private static string HashGlobalProps(IDictionary globalProperties) 52 | { 53 | using (var sha1 = SHA1.Create()) 54 | { 55 | var stringBuilder = new StringBuilder(); 56 | foreach (var item in globalProperties) 57 | { 58 | stringBuilder.Append(item.Key); 59 | stringBuilder.Append(ItemSeparatorCharacter); 60 | stringBuilder.Append(item.Value); 61 | } 62 | 63 | var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(stringBuilder.ToString())); 64 | 65 | stringBuilder.Clear(); 66 | 67 | foreach (var b in hash) 68 | { 69 | stringBuilder.Append(b.ToString("x2")); 70 | } 71 | 72 | return stringBuilder.ToString(); 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/GraphGen/SolutionParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text.RegularExpressions; 7 | 8 | namespace GraphGen 9 | { 10 | public static class SolutionParser 11 | { 12 | private static readonly Regex SolutionFileRegex = new Regex( 13 | @"^Project\(""\{(?[\wA-F]{8}-[\wA-F]{4}-[\wA-F]{4}-[\wA-F]{4}-[\wA-F]{12})\}""\) = ""(?.+)"", ""(?.+)"", ""\{(?[\wA-F]{8}-[\wA-F]{4}-[\wA-F]{4}-[\wA-F]{4}-[\wA-F]{12})\}""\r?$", 14 | RegexOptions.Multiline | RegexOptions.Compiled); 15 | 16 | private static readonly IReadOnlyDictionary ProjectTypeNamedGuids = 17 | new Dictionary(StringComparer.OrdinalIgnoreCase) 18 | { 19 | {"vbProjectGuid", "F184B08F-C81C-45F6-A57F-5ABD9991F28F"}, 20 | {"csProjectGuid", "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC"}, 21 | {"cpsProjectGuid", "13B669BE-BB05-4DDF-9536-439F39A36129"}, 22 | {"cpsCsProjectGuid", "9A19103F-16F7-4668-BE54-9A1E7A4F7556"}, 23 | {"cpsVbProjectGuid", "778DAE3C-4631-46EA-AA77-85C1314464D9"}, 24 | {"vjProjectGuid", "E6FDF86B-F3D1-11D4-8576-0002A516ECE8"}, 25 | {"vcProjectGuid", "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942"}, 26 | {"fsProjectGuid", "F2A71F9B-5D33-465A-A702-920D77279786"}, 27 | {"dbProjectGuid", "C8D11400-126E-41CD-887F-60BD40844F9E"}, 28 | {"wdProjectGuid", "2CFEAB61-6A3B-4EB8-B523-560B4BEEF521"}, 29 | {"webProjectGuid", "E24C65DC-7377-472B-9ABA-BC803B73C61A"} 30 | }; 31 | 32 | private static readonly IReadOnlyCollection ProjectTypeGuids = ProjectTypeNamedGuids.Values.ToHashSet(StringComparer.OrdinalIgnoreCase); 33 | 34 | public static IEnumerable GetProjectFiles(string solutionFile) 35 | { 36 | Trace.Assert(File.Exists(solutionFile), $"Solution file does not exist: {solutionFile}"); 37 | 38 | var matches = SolutionFileRegex.Matches(File.ReadAllText(solutionFile)); 39 | 40 | var solutionDirectory = Path.GetDirectoryName(solutionFile); 41 | 42 | Trace.Assert(solutionDirectory != null); 43 | 44 | foreach (Match match in matches) 45 | { 46 | var projectTypeGuids = match.Groups["ProjectTypeGuid"].Captures.GetEnumerator().ToEnumerable().OfType().ToArray(); 47 | 48 | Trace.Assert(projectTypeGuids.Length == 1, "A solution project must have a single project type guid"); 49 | 50 | // reject entries we're not interested in (e.g. solution folders) 51 | if (!ProjectTypeGuids.Contains(projectTypeGuids.First().Value)) 52 | { 53 | continue; 54 | } 55 | 56 | var projectFileGroup = match.Groups["ProjectFile"].Captures.GetEnumerator().ToEnumerable().OfType().ToArray(); 57 | 58 | Trace.Assert(projectFileGroup.Length == 1, "A solution project must have a single file"); 59 | 60 | yield return Path.Combine(solutionDirectory, projectFileGroup.First().Value); 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/GraphGen/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/GraphGen/nuget.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/MSBuildGraphForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace MSBuildGraphUI 2 | { 3 | partial class MSBuildGraphForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this._loadButton = new System.Windows.Forms.Button(); 32 | this._openFileDialog = new System.Windows.Forms.OpenFileDialog(); 33 | this._statusBar = new System.Windows.Forms.StatusStrip(); 34 | this._statusBarLabel = new System.Windows.Forms.ToolStripStatusLabel(); 35 | this.tabControl1 = new System.Windows.Forms.TabControl(); 36 | this.tabPage1 = new System.Windows.Forms.TabPage(); 37 | this._propertyGrid = new System.Windows.Forms.PropertyGrid(); 38 | this._treeVew = new System.Windows.Forms.TreeView(); 39 | this.tabPage2 = new System.Windows.Forms.TabPage(); 40 | this.webBrowser1 = new System.Windows.Forms.WebBrowser(); 41 | this._statusBar.SuspendLayout(); 42 | this.tabControl1.SuspendLayout(); 43 | this.tabPage1.SuspendLayout(); 44 | this.tabPage2.SuspendLayout(); 45 | this.SuspendLayout(); 46 | // 47 | // _loadButton 48 | // 49 | this._loadButton.Location = new System.Drawing.Point(12, 12); 50 | this._loadButton.Name = "_loadButton"; 51 | this._loadButton.Size = new System.Drawing.Size(94, 28); 52 | this._loadButton.TabIndex = 1; 53 | this._loadButton.Text = "Load Project"; 54 | this._loadButton.UseVisualStyleBackColor = true; 55 | this._loadButton.Click += new System.EventHandler(this._loadButton_Click); 56 | // 57 | // _openFileDialog 58 | // 59 | this._openFileDialog.Filter = "Projects|*.*proj;*.sln"; 60 | // 61 | // _statusBar 62 | // 63 | this._statusBar.ImageScalingSize = new System.Drawing.Size(24, 24); 64 | this._statusBar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 65 | this._statusBarLabel}); 66 | this._statusBar.Location = new System.Drawing.Point(0, 690); 67 | this._statusBar.Name = "_statusBar"; 68 | this._statusBar.Size = new System.Drawing.Size(1103, 22); 69 | this._statusBar.TabIndex = 2; 70 | this._statusBar.Text = "statusStrip1"; 71 | // 72 | // _statusBarLabel 73 | // 74 | this._statusBarLabel.Name = "_statusBarLabel"; 75 | this._statusBarLabel.Size = new System.Drawing.Size(0, 15); 76 | // 77 | // tabControl1 78 | // 79 | this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 80 | | System.Windows.Forms.AnchorStyles.Left) 81 | | System.Windows.Forms.AnchorStyles.Right))); 82 | this.tabControl1.Controls.Add(this.tabPage1); 83 | this.tabControl1.Controls.Add(this.tabPage2); 84 | this.tabControl1.Location = new System.Drawing.Point(0, 46); 85 | this.tabControl1.Name = "tabControl1"; 86 | this.tabControl1.SelectedIndex = 0; 87 | this.tabControl1.Size = new System.Drawing.Size(1103, 641); 88 | this.tabControl1.TabIndex = 4; 89 | // 90 | // tabPage1 91 | // 92 | this.tabPage1.Controls.Add(this._propertyGrid); 93 | this.tabPage1.Controls.Add(this._treeVew); 94 | this.tabPage1.Location = new System.Drawing.Point(4, 22); 95 | this.tabPage1.Name = "tabPage1"; 96 | this.tabPage1.Padding = new System.Windows.Forms.Padding(3); 97 | this.tabPage1.Size = new System.Drawing.Size(1095, 615); 98 | this.tabPage1.TabIndex = 0; 99 | this.tabPage1.Text = "Tree"; 100 | this.tabPage1.UseVisualStyleBackColor = true; 101 | // 102 | // _propertyGrid 103 | // 104 | this._propertyGrid.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 105 | | System.Windows.Forms.AnchorStyles.Right))); 106 | this._propertyGrid.Location = new System.Drawing.Point(743, 6); 107 | this._propertyGrid.Name = "_propertyGrid"; 108 | this._propertyGrid.Size = new System.Drawing.Size(344, 616); 109 | this._propertyGrid.TabIndex = 5; 110 | // 111 | // _treeVew 112 | // 113 | this._treeVew.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 114 | | System.Windows.Forms.AnchorStyles.Left) 115 | | System.Windows.Forms.AnchorStyles.Right))); 116 | this._treeVew.Location = new System.Drawing.Point(0, 0); 117 | this._treeVew.Name = "_treeVew"; 118 | this._treeVew.Size = new System.Drawing.Size(737, 615); 119 | this._treeVew.TabIndex = 4; 120 | this._treeVew.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this._treeVew_AfterSelect_1); 121 | // 122 | // tabPage2 123 | // 124 | this.tabPage2.Controls.Add(this.webBrowser1); 125 | this.tabPage2.Location = new System.Drawing.Point(4, 22); 126 | this.tabPage2.Name = "tabPage2"; 127 | this.tabPage2.Padding = new System.Windows.Forms.Padding(3); 128 | this.tabPage2.Size = new System.Drawing.Size(1095, 615); 129 | this.tabPage2.TabIndex = 1; 130 | this.tabPage2.Text = "Graph"; 131 | this.tabPage2.UseVisualStyleBackColor = true; 132 | // 133 | // webBrowser1 134 | // 135 | this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill; 136 | this.webBrowser1.Location = new System.Drawing.Point(3, 3); 137 | this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20); 138 | this.webBrowser1.Name = "webBrowser1"; 139 | this.webBrowser1.Size = new System.Drawing.Size(1089, 609); 140 | this.webBrowser1.TabIndex = 6; 141 | // 142 | // Form1 143 | // 144 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 145 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 146 | this.ClientSize = new System.Drawing.Size(1103, 712); 147 | this.Controls.Add(this.tabControl1); 148 | this.Controls.Add(this._statusBar); 149 | this.Controls.Add(this._loadButton); 150 | this.Name = "Form1"; 151 | this.Text = "MS Build Graph Visualizer"; 152 | this._statusBar.ResumeLayout(false); 153 | this._statusBar.PerformLayout(); 154 | this.tabControl1.ResumeLayout(false); 155 | this.tabPage1.ResumeLayout(false); 156 | this.tabPage2.ResumeLayout(false); 157 | this.ResumeLayout(false); 158 | this.PerformLayout(); 159 | 160 | } 161 | 162 | #endregion 163 | private System.Windows.Forms.Button _loadButton; 164 | private System.Windows.Forms.OpenFileDialog _openFileDialog; 165 | private System.Windows.Forms.StatusStrip _statusBar; 166 | private System.Windows.Forms.ToolStripStatusLabel _statusBarLabel; 167 | private System.Windows.Forms.TabControl tabControl1; 168 | private System.Windows.Forms.TabPage tabPage1; 169 | private System.Windows.Forms.PropertyGrid _propertyGrid; 170 | private System.Windows.Forms.TreeView _treeVew; 171 | private System.Windows.Forms.TabPage tabPage2; 172 | private System.Windows.Forms.WebBrowser webBrowser1; 173 | } 174 | } 175 | 176 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/MSBuildGraphForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Diagnostics; 7 | using System.Drawing; 8 | using System.IO; 9 | using System.Linq; 10 | using System.Security.Cryptography; 11 | using System.Text; 12 | using System.Threading; 13 | using System.Threading.Tasks; 14 | using System.Windows.Forms; 15 | using GraphGen; 16 | using Microsoft.Build.Evaluation; 17 | using Microsoft.Build.Execution; 18 | using Microsoft.Build.Graph; 19 | using MSBuildGraphUI.WG; 20 | using Newtonsoft.Json; 21 | 22 | namespace MSBuildGraphUI 23 | { 24 | public partial class MSBuildGraphForm : Form 25 | { 26 | public MSBuildGraphForm() 27 | { 28 | InitializeComponent(); 29 | } 30 | 31 | private void _loadButton_Click(object sender, EventArgs e) 32 | { 33 | if (_openFileDialog.ShowDialog(this) == DialogResult.OK) 34 | { 35 | LoadGraph(new FileInfo(_openFileDialog.FileName)); 36 | } 37 | 38 | } 39 | 40 | private async void LoadGraph(FileInfo project) 41 | { 42 | var files = new List(); 43 | 44 | if (project.Extension == ".sln") 45 | { 46 | files.AddRange(SolutionParser.GetProjectFiles(project.FullName) 47 | .Select(f => new ProjectGraphEntryPoint(f))); 48 | } 49 | else 50 | { 51 | files.Add(new ProjectGraphEntryPoint(project.FullName)); 52 | } 53 | 54 | _statusBarLabel.Text = $@"Loading {project.FullName}..."; 55 | 56 | // Load the graph from MSBuild 57 | var stopwatch = Stopwatch.StartNew(); 58 | var graph = await Task.Factory.StartNew(() => 59 | new ProjectGraph(files, ProjectCollection.GlobalProjectCollection, ProjectInstanceFactory)); 60 | stopwatch.Stop(); 61 | 62 | _statusBarLabel.Text = $@"{project.Name} loaded {graph.ProjectNodes.Count} node(s) in {stopwatch.ElapsedMilliseconds}ms."; 63 | 64 | var projects = new ConcurrentDictionary(); 65 | 66 | foreach (var item in graph.ProjectNodes) 67 | { 68 | var propsHash = HashGlobalProps(item.ProjectInstance.GlobalProperties); 69 | projects.TryAdd(item.ProjectInstance.FullPath + propsHash, item); 70 | } 71 | 72 | var graphText = await Task.Factory.StartNew(() => GraphGen.GraphVis.Create(projects)); 73 | var t = Path.GetTempFileName(); 74 | var file = Path.GetTempPath() + "MSB_GRAPH.png"; 75 | await Task.Factory.StartNew(() => GraphGen.GraphVis.SaveAsPng(graphText, file)); 76 | 77 | webBrowser1.Url = new Uri(file); 78 | 79 | _statusBarLabel.Text = $@"{project.Name} loaded {graph.ProjectNodes.Count} node(s) in {stopwatch.ElapsedMilliseconds}ms. Populating the TreeView..."; 80 | var stopwatch2 = Stopwatch.StartNew(); 81 | await Task.Factory.StartNew(() => PopulateTree(graph)); 82 | stopwatch2.Stop(); 83 | _statusBarLabel.Text = $@"{project.Name} loaded {graph.ProjectNodes.Count} node(s) in {stopwatch.ElapsedMilliseconds}ms. {stopwatch2.ElapsedMilliseconds}ms to draw {_counts} nodes in the TreeView."; 84 | } 85 | 86 | private ProjectInstance ProjectInstanceFactory(string projectFile, Dictionary globalProperties, ProjectCollection projectCollection) 87 | { 88 | Action a = () => _statusBarLabel.Text = $@"Loading {projectFile}..."; 89 | this.Invoke(a); 90 | 91 | var sw = Stopwatch.StartNew(); 92 | var pi = new ProjectInstance( 93 | projectFile, 94 | globalProperties, 95 | "Current", 96 | projectCollection); 97 | sw.Stop(); 98 | 99 | Action a2 = () => _statusBarLabel.Text = $@"Loading {projectFile}. Done in {sw.ElapsedMilliseconds}ms"; 100 | this.Invoke(a2); 101 | 102 | return pi; 103 | } 104 | 105 | private void PopulateTree(ProjectGraph graph) 106 | { 107 | Action a1 = () => _treeVew.Nodes.Clear(); 108 | this.Invoke(a1); 109 | 110 | foreach (var root in graph.GraphRoots) 111 | { 112 | Action a = () => _treeVew.Nodes.Add(AdaptGraphNode(root)); 113 | this.Invoke(a); 114 | 115 | } 116 | } 117 | 118 | private int _counts = 0; 119 | 120 | private TreeNode AdaptGraphNode(ProjectGraphNode node) 121 | { 122 | Interlocked.Increment(ref _counts); 123 | TreeNode treeNode = new TreeNode(node.ProjectInstance.FullPath) {Tag = node}; 124 | 125 | foreach (var child in node.ProjectReferences) 126 | { 127 | treeNode.Nodes.Add(AdaptGraphNode(child)); 128 | } 129 | 130 | return treeNode; 131 | } 132 | 133 | private const char ItemSeparatorCharacter = '\u2028'; 134 | 135 | private static string HashGlobalProps(IDictionary globalProperties) 136 | { 137 | using (var sha1 = SHA1.Create()) 138 | { 139 | var stringBuilder = new StringBuilder(); 140 | foreach (var item in globalProperties) 141 | { 142 | stringBuilder.Append(item.Key); 143 | stringBuilder.Append(ItemSeparatorCharacter); 144 | stringBuilder.Append(item.Value); 145 | } 146 | 147 | var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(stringBuilder.ToString())); 148 | 149 | stringBuilder.Clear(); 150 | 151 | foreach (var b in hash) 152 | { 153 | stringBuilder.Append(b.ToString("x2")); 154 | } 155 | 156 | return stringBuilder.ToString(); 157 | } 158 | } 159 | 160 | private void _treeVew_AfterSelect_1(object sender, TreeViewEventArgs e) 161 | { 162 | var graphNode = (ProjectGraphNode)e.Node.Tag; 163 | //_propertyGrid.SelectedObject = new { Name = graphNode.ProjectInstance.FullPath, Props = graphNode.ProjectInstance.GlobalProperties}; 164 | _propertyGrid.SelectedObject = graphNode.ProjectInstance; 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/MSBuildGraphForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 156, 17 125 | 126 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/MSBuildGraphUI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1C2C61EF-C498-406E-A33A-64E6158E6C93} 8 | WinExe 9 | MSBuildGraphUI 10 | MSBuildGraphUI 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | 18 | 19 | 20 | AnyCPU 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | AnyCPU 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | true 40 | bin\x64\Debug\ 41 | DEBUG;TRACE 42 | full 43 | x64 44 | prompt 45 | MinimumRecommendedRules.ruleset 46 | true 47 | 48 | 49 | bin\x64\Release\ 50 | TRACE 51 | true 52 | pdbonly 53 | x64 54 | prompt 55 | MinimumRecommendedRules.ruleset 56 | true 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Form 74 | 75 | 76 | MSBuildGraphForm.cs 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | MSBuildGraphForm.cs 85 | 86 | 87 | ResXFileCodeGenerator 88 | Resources.Designer.cs 89 | Designer 90 | 91 | 92 | True 93 | Resources.resx 94 | True 95 | 96 | 97 | SettingsSingleFileGenerator 98 | Settings.Designer.cs 99 | 100 | 101 | True 102 | Settings.settings 103 | True 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 2.38.0.2 112 | none 113 | all 114 | true 115 | 116 | 117 | 1.4.1 118 | 119 | 120 | 12.0.1 121 | 122 | 123 | 124 | 125 | {8bae078e-9add-477f-bfa2-59956452640f} 126 | GraphGen 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | using Microsoft.Build.Locator; 7 | 8 | namespace MSBuildGraphUI 9 | { 10 | static class Program 11 | { 12 | /// 13 | /// The main entry point for the application. 14 | /// 15 | [STAThread] 16 | static void Main() 17 | { 18 | //var msbuildPath = @"D:\src\msbuild.fork\artifacts\bin\bootstrap\net472\MSBuild\Current\Bin"; 19 | //var msbuildPath = @"D:\src\msbuild\artifacts\Debug\bootstrap\net472\MSBuild\15.0\Bin"; 20 | //var msbuildPath = @"D:\src\DomTest\SGEC\src\rps\MSBuild\artifacts\bin\bootstrap\net472\MSBuild\Current\Bin"; 21 | var instances = MSBuildLocator.QueryVisualStudioInstances(VisualStudioInstanceQueryOptions.Default); 22 | var instance = instances.FirstOrDefault(i => i.Version.Major == 17); 23 | MSBuildLocator.RegisterInstance(instance); 24 | //MSBuildLocator.RegisterMSBuildPath(msbuildPath); 25 | 26 | Application.EnableVisualStyles(); 27 | Application.SetCompatibleTextRenderingDefault(false); 28 | Application.Run(new MSBuildGraphForm()); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("MSBuildGraphUI")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MSBuildGraphUI")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1c2c61ef-c498-406e-a33a-64e6158e6c93")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace MSBuildGraphUI.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MSBuildGraphUI.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace MSBuildGraphUI.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/WG/WGEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MSBuildGraphUI.WG 8 | { 9 | public class WgEdge 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/WG/WGNode.cs: -------------------------------------------------------------------------------- 1 | namespace MSBuildGraphUI.WG 2 | { 3 | public class WgNode 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/MSBuildGraphUI/WG/WebGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Security.Cryptography; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Microsoft.Build.Graph; 10 | 11 | namespace MSBuildGraphUI.WG 12 | { 13 | public class WebGraph 14 | { 15 | public static string Create(ProjectGraph graph) 16 | { 17 | StringBuilder sb = new StringBuilder(); 18 | 19 | var projects = new ConcurrentDictionary(); 20 | foreach (var item in graph.ProjectNodes) 21 | { 22 | var propsHash = HashGlobalProps(item.ProjectInstance.GlobalProperties); 23 | projects.TryAdd(item.ProjectInstance.FullPath + propsHash, item); 24 | } 25 | 26 | var indent = "\t"; 27 | sb.AppendLine("digraph prof {"); 28 | sb.AppendLine(indent + "ratio = fill;"); 29 | sb.AppendLine(indent + "node [style=filled];"); 30 | 31 | foreach (var node in projects) 32 | { 33 | if (node.Value.ProjectInstance.FullPath.Contains("dirs.proj")) 34 | { 35 | continue; 36 | } 37 | 38 | foreach (var subnode in node.Value.ProjectReferences) 39 | { 40 | var n1 = Path.GetFileNameWithoutExtension(node.Value.ProjectInstance.FullPath).Replace(".", "_"); 41 | var n2 = Path.GetFileNameWithoutExtension(subnode.ProjectInstance.FullPath).Replace(".", "_"); 42 | sb.AppendLine($"{indent}{n1} -> {n2} [color=\"0.002 0.999 0.999\"];"); 43 | } 44 | } 45 | 46 | sb.AppendLine("}"); 47 | return sb.ToString(); 48 | } 49 | 50 | private const char ItemSeparatorCharacter = '\u2028'; 51 | 52 | private static string HashGlobalProps(IDictionary globalProperties) 53 | { 54 | using (var sha1 = SHA1.Create()) 55 | { 56 | var stringBuilder = new StringBuilder(); 57 | foreach (var item in globalProperties) 58 | { 59 | stringBuilder.Append(item.Key); 60 | stringBuilder.Append(ItemSeparatorCharacter); 61 | stringBuilder.Append(item.Value); 62 | } 63 | 64 | var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(stringBuilder.ToString())); 65 | 66 | stringBuilder.Clear(); 67 | 68 | foreach (var b in hash) 69 | { 70 | stringBuilder.Append(b.ToString("x2")); 71 | } 72 | 73 | return stringBuilder.ToString(); 74 | } 75 | } 76 | 77 | } 78 | } 79 | --------------------------------------------------------------------------------