Having a diagram of how your Visual Studio projects interlink, can be a big help. I’ve created a small PowerShell script that will produce the diagram based on the .csproj projects in a solution directory. It will generate yUML diagrams like this: Yuml diagram

The basic idea

We’re taking advantage of the fact that¬†.csproj¬†files for .Net Core are XML files. This means they can be queried by¬†Select-Xml.

  1. Find all .csproj files recursively.
  2. Exclude the test projects.
  3. Find all referenced project by querying the//ProjectReference/@Include nodes.
  4. Map each reference to the project by generating a [Project]->[Reference] string.
  5. Join all string into a single string with the url-encoded value of¬†“, “ =>¬†“%2C%20”.
  6. Expand this string to a yuml.me URL.
  7. Launch the URL in the browser.

The script

The following code will open up a browser with the diagram.

Open up PowerShell. cd or pushd to the solution directory. Paste the script and enjoy!

Listing Nuget packagess

If you like to create a diagram of both project and Nuget packages, you can use the following script (the Select-Xml statement is now changed). Note: these diagrams are very large. Some URLs are way too big to start. Handle with care!

The diagram will be way bigger:

The URL that the script generates is:¬†https://yuml.me/diagram/plain/class/[KeesTalksTech.Assessments.Wehka…

Pretty cool, right? Thanks to the guys of yuml.me!