sln2mermaid is a minimal .NET console application that reads .sln, .slnx, and .csproj files and renders project-to-project references as a Mermaid dependency diagram.
Version 0.4 only visualizes <ProjectReference /> relationships. It does not inspect package references, infer architecture layers, group projects by folders, or evaluate MSBuild conditions.
- Load one or more
.sln,.slnx, and/or.csprojinput files. - Discover
.csprojprojects listed in solution files. - Parse
<ProjectReference Include="..." />entries from project files. - Resolve project references transitively.
- Deduplicate projects and edges across all inputs.
- Print Mermaid diagram text to stdout.
- Write Mermaid diagram text to the path provided with
--outor tosln2mermaid.mmdby default. - Optionally export the Mermaid diagram to PNG or SVG through Docker.
- Optionally group projects by detected project type metadata.
dotnet build sln2mermaid.slnxdotnet run --project src/Sln2Mermaid -- ./MySolution.slnx
dotnet run --project src/Sln2Mermaid -- ./MySolution.slnx --out graph.mmd
dotnet run --project src/Sln2Mermaid -- --in ./src/MyProject/MyProject.csproj --out graph.mmd
dotnet run --project src/Sln2Mermaid -- --in ./A.slnx ./B.csproj --out graph.mmdSupported options:
--in <file...>reads one or more.sln,.slnx, or.csprojfiles. Positional input paths are also supported.--out <file>writes the Mermaid source to a.mmdfile. If omitted,sln2mermaid.mmdis used.--group-by-typegroups nodes into Mermaid subgraphs by detected project type metadata.--png <file>renders a PNG file.--png-scale <1-10>optionally sets the PNG render scale in case a lot of projects specified. Higher values improve sharpness but increase file size, render time, and memory use. By default, no explicit scale is passed to Mermaid CLI.--svg <file>renders an SVG file.
Use --group-by-type to group projects into Mermaid subgraphs based on project metadata:
dotnet run --project src/Sln2Mermaid -- MySolution.sln --group-by-type
dotnet run --project src/Sln2Mermaid -- MySolution.sln --group-by-type --out deps.mmd
dotnet run --project src/Sln2Mermaid -- MySolution.sln --group-by-type --png deps.pngThis is grouping by project metadata. It is not architectural inference and does not classify projects as Domain, Infrastructure, Application, or UI.
Buckets are rendered in this stable order when they contain projects:
- Web
- Worker
- Console
- Tests
- Library
- Unknown
Detection is deterministic and intentionally simple:
Tests:<IsTestProject>true</IsTestProject>, common test package references, or names containing markers such as.Tests,.UnitTests,.IntegrationTests,.FunctionalTests, or.Test.Web: root project SDK containsMicrosoft.NET.Sdk.Web.Worker: root project SDK containsMicrosoft.NET.Sdk.Worker.Console:<OutputType>Exe</OutputType>after Tests/Web/Worker checks.Library: SDK-style non-executable projects that are not classified above.Unknown: missing or ambiguous project metadata.
The repository includes an Acme Company demo solution under samples/AcmeCompany.
Generate a flat diagram:
dotnet run --project src/Sln2Mermaid -- --in samples/AcmeCompany/AcmeCompany.slnx --out samples/AcmeCompany/diagrams/acme-default.mmdgraph TD
N1["Acme.Application"]
N2["Acme.Application.Tests"]
N3["Acme.Console"]
N4["Acme.Core"]
N5["Acme.Infrastructure"]
N6["Acme.WebApi"]
N7["Acme.WebUi"]
N8["Acme.Worker"]
N1 --> N4
N2 --> N1
N3 --> N1
N5 --> N4
N6 --> N1
N6 --> N5
N7 --> N1
N8 --> N1
N8 --> N5
Generate a grouped-by-type diagram:
dotnet run --project src/Sln2Mermaid -- --in samples/AcmeCompany/AcmeCompany.slnx --group-by-type --out samples/AcmeCompany/diagrams/acme-grouped-by-type.mmdgraph TD
subgraph Web
N6["Acme.WebApi"]
N7["Acme.WebUi"]
end
subgraph Worker
N8["Acme.Worker"]
end
subgraph Console
N3["Acme.Console"]
end
subgraph Tests
N2["Acme.Application.Tests"]
end
subgraph Library
N1["Acme.Application"]
N4["Acme.Core"]
N5["Acme.Infrastructure"]
end
N1 --> N4
N2 --> N1
N3 --> N1
N5 --> N4
N6 --> N1
N6 --> N5
N7 --> N1
N8 --> N1
N8 --> N5
PNG and SVG export require Docker to be installed and running. Mermaid CLI must not be installed locally for this tool. The app runs Mermaid CLI only inside the minlag/mermaid-cli Docker container, and only when --png or --svg is requested.
dotnet run --project src/Sln2Mermaid -- --in ./MySolution.slnx --out deps.mmd --png deps.png
dotnet run --project src/Sln2Mermaid -- --in ./MyBigSolution.slnx --out deps.mmd --png deps.png --png-scale 4
dotnet run --project src/Sln2Mermaid -- --in ./MySolution.slnx --out deps.mmd --svg deps.svg
dotnet run --project src/Sln2Mermaid -- --in ./MySolution.slnx --out deps.mmd --png deps.png --svg deps.svgImage export runs a temporary .mmd file through the Mermaid CLI container image:
docker run --rm -v <host_dir>:/data minlag/mermaid-cli -i /data/input.mmd -o /data/output.pngThe app always writes the requested .mmd file first. For image export, it also creates a temporary directory, writes diagram.mmd, mounts that directory as /data, runs docker run --rm, copies the generated PNG/SVG to the requested output path, and removes the temporary directory. Docker is required only for PNG/SVG export.
PNG output is rasterized. Use --png-scale to trade file size and render cost for sharper PNG output. For large diagrams, SVG is usually the better format because it remains sharp at any zoom level.
Very large solutions can become hard to read as a single diagram regardless of image format. If a solution has many projects and dense dependencies, consider generating diagrams for smaller solution/project subsets instead of relying on one huge PNG.
graph TD
N1["Company.Core"]
N2["Company.Core.Abstractions"]
N3["Company.ProjectLogic"]
N4["Company.Tasks"]
N1 --> N2
N3 --> N1
N4 --> N1
N4 --> N3
Project names are rendered as Mermaid labels. Generated node ids such as N1, N2, and N3 are used so project names with dots or other punctuation remain valid.
The repository includes a small no-package console test harness:
dotnet run --project tests/Sln2Mermaid.Tests- Only
.sln,.slnx, and.csprojinputs are supported. - Only project-to-project references are included.
PackageReferencedependencies are used only for test project detection; package dependency edges are ignored.- MSBuild properties, imports, targets, and conditions are not evaluated.
- Solution folders are ignored.
- PNG and SVG export depend on Docker and are not rendered natively by this app.
--group-by-typeis project metadata grouping, not architecture classification.