Create Solutions & Class Diagrams with SolutionUtil (slnutil)

November 01, 2024
Cover Image

I've been using some updates to my slnutil project lately and I wanted to mention a couple of new features. As a refresher on what slnutil is, it's a bunch of utilities for working with .NET Core Solutions and Projects. The idea is that the features of slnutil help you to do things that can be a little painful or simply just aren't there in Visual Studio, Visual Studio Code, or the .NET Core CLI.

The two new features:

  • Create class diagrams from a .NET Assembly
  • Create .NET Core solutions from the command line for various types of projects

How to Install slnutil

Solution Util is a dotnet tool that's available for free on NuGet. To install it, just pop down to your command line interface and type

dotnet tool install slnutil -g

That'll make the tool available to you so that all you need to do to run it is type "slnutil" on the command line.

Feature: Create Entire Solutions & Projects using slnutil

Another new feature is the ability to create entire solutions. The idea here is that you can quickly create an entire solution with all the projects plus all the project references and all the package references from the command line. The main reason I wrote this one was so that I quickly had a way to create .NET MAUI projects with xUnit tests. You can create those MAUI + xUnit projects right now but it involves editing the csproj file by hand.

I created templates for:

Here's an example of creating a .NET MAUI demo solution:

slnutil createsolution maui-demo Benday.MauiDemo123

When you run this command, it'll create a solution named Benday.MauiDemo123.sln with a structure that looks like this. The maui-demo template option creates the projects you see in the image below and adds a demo application with ViewModels and unit tests.

Demo App Code in Solution Explorer

If you run it, you'll see a demo app that looks like the one in the image below.

.NET MAUI Demo Application

Feature: Create Class Diagrams from a .NET Assembly

I found myself needing some UML Class Diagrams for a conference presentation that I'm writing. There's a feature called "Class Diagrams" in Visual Studio 2022 that will do this for you but 1) it's not installed by default, 2) it's not available on the ARM64 version of Visual Studio, and 3) it can be a little tricky to work with. And if you work on Mac or Linux, it's not available at all. So I added the feature to slnutil.

Let's say that you have a .NET Core DLL and you'd like to get a class diagram for it. For demo purposes, I'm going to use the Benday.CosmosDb.dll file from my CosmosDb library.

Go to the directory that has that DLL, and then type:

slnutil classdiagram Benday.CosmosDb.dll

Run that command and I get the following diagram.

Unfiltered Class Diagram for Benday.CosmosDb

If you want to filter it to just show specific classes and interfaces, you can use the /typenames argument. If you want to filter by namespace, use the /namespace option. Here's that same DLL filtered by namespaces that contain the word "repositories".

slnutil classdiagram Benday.CosmosDb.dll /namespace:repositories

This gives us a more focused class diagram like the image below.

Filtered Class Diagram for Benday.CosmosDb

Summary

Anyway, those are the two new features in slnutil. There are a ton of other features in slnutil, too. If you've got ideas for other new features or you find bugs, let me know.

-Ben

Categories: net-core