Skip to content

Commit

Permalink
updated to ilspycmd API
Browse files Browse the repository at this point in the history
  • Loading branch information
h0lg committed Nov 11, 2024
1 parent bed4227 commit 9344123
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions ICSharpCode.ILSpyX/MermaidDiagrammer/ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- title: netAmermaid --> <!-- of the printed HTML see https://github.com/yzhang-gh/vscode-markdown#print-markdown-to-html -->
# netAmermaid <!-- omit in toc -->
<!-- title: Generating diagrammers --> <!-- of the printed HTML see https://github.com/yzhang-gh/vscode-markdown#print-markdown-to-html -->
# Generating diagrammers <!-- omit in toc -->

An automated documentation tool for visually exploring
[.NET assemblies](https://learn.microsoft.com/en-us/dotnet/standard/assembly/) (_*.dll_ files)
Expand Down Expand Up @@ -37,7 +37,7 @@ And what's the point? Like any other hand-crafted documentation, **they're alway
After a while their usability becomes a function of **how much time you want to spend maintaining** them.
Also, they're next to useless in conversations about the *boundaries* of whatever subdomain or Aggregate you're looking at - because they **lack the interactivity to let you peek beyond the boundary**.

**netAmermaid** helps you create useful on-the-fly class diagrams within seconds in two simple steps:
**ilspycmd** helps you create useful on-the-fly class diagrams within seconds in two simple steps:

1. Point the **command line tool** at an assembly to extract its type information
and **build a [HTML5](https://en.wikipedia.org/wiki/HTML5#New_APIs) diagramming app** from it.
Expand All @@ -56,7 +56,7 @@ Generated diagrammers offer an **overview** over types, their members and **rela

# How does it work?

To **extract the type info from the source assembly**, the netAmermaid CLI side-loads it including all its dependencies.
To **extract the type info from the source assembly**, the ilspycmd CLI side-loads it including all its dependencies.
The current implementation actually uses ILSpy under the hood for that because it's really good at figuring out [which runtime, GAC or private bin path to load referenced assemblies from](https://github.com/icsharpcode/ILSpy/blob/master/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs).

The extracted type info is **structured into a model optimized for the HTML diagrammer** and serialized to JSON. The model is a mix between drop-in type definitions in mermaid class diagram syntax and destructured metadata about relations, inheritance and documentation comments.
Expand Down Expand Up @@ -108,18 +108,18 @@ to generate a HTML diagrammer from a .Net assembly using the console app.
Using the CMD shell in a Windows environment for example, you'd create a `regenerate.cmd` looking somewhat like this:

<pre>
..\..\path\to\netAmermaid.exe --assembly ..\path\to\your\assembly.dll --output-folder .
..\..\path\to\ilspycmd.exe ..\path\to\your\assembly.dll --generate-diagrammer --outputdir .
</pre>

With this script in place, run it to (re-)generate the HTML diagrammer at your leisure. Note that `--output-folder .` directs the output to the current directory.
With this script in place, run it to (re-)generate the HTML diagrammer at your leisure. Note that `--outputdir .` directs the output to the current directory.

## Automatically

If you want to deploy an up-to-date HTML diagrammer as part of your live documentation,
you'll want to automate its regeneration to keep it in sync with your code base.

For example, you might like to share the diagrammer on a web server or - in general - with users
who cannot or may not regenerate it; lacking either access to the netAmermaid console app or permission to use it.
who cannot or may not regenerate it; lacking either access to the ilspycmd console app or permission to use it.

In such cases, you can dangle the regeneration off the end of either your build or deployment pipeline.
Note that the macros used here apply to [MSBuild](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild) for [Visual Studio](https://learn.microsoft.com/en-us/visualstudio/ide/reference/pre-build-event-post-build-event-command-line-dialog-box) and your mileage may vary with VS for Mac or VS Code.
Expand All @@ -132,7 +132,7 @@ Note that the `Condition` here is optional and configures this step to only run

```xml
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Release'">
<Exec Command="$(SolutionDir)..\path\to\netAmermaid.exe --assembly $(TargetPath) --output-folder $(ProjectDir)netAmermaid" />
<Exec Command="$(SolutionDir)..\path\to\ilspycmd.exe $(TargetPath) --generate-diagrammer --outputdir $(ProjectDir)diagrammer" />
</Target>
```

Expand All @@ -143,7 +143,7 @@ Note that the `Target` `Name` doesn't matter here and that the diagrammer is gen

```xml
<Target Name="GenerateHtmlDiagrammer" AfterTargets="Publish">
<Exec Command="$(SolutionDir)..\path\to\netAmermaid.exe --assembly $(TargetPath) --output-folder $(PublishDir)netAmermaid" />
<Exec Command="$(SolutionDir)..\path\to\ilspycmd.exe $(TargetPath) --generate-diagrammer --outputdir $(PublishDir)diagrammer" />
</Target>
```

Expand All @@ -152,7 +152,7 @@ Note that the `Target` `Name` doesn't matter here and that the diagrammer is gen
**Compiler-generated** types and their nested types are **excluded by default**.

Consider sussing out **big source assemblies** using [ILSpy](https://github.com/icsharpcode/ILSpy) first to get an idea about which subdomains to include in your diagrammers. Otherwise you may experience long build times and large file sizes for the diagrammer as well as a looong type selection opening it. At some point, mermaid may refuse to render all types in your selection because their definitions exceed the maximum input size. If that's where you find yourself, you may want to consider
- using `--include` and `--exclude` to **limit the scope of the individual diagrammer to a certain subdomain**
- using `--generate-diagrammer-include` and `--generate-diagrammer-exclude` to **limit the scope of the individual diagrammer to a certain subdomain**
- generating **multiple diagrammers for different subdomains**.

## Advanced configuration examples
Expand All @@ -164,11 +164,11 @@ Above examples show how the most important options are used. Let's have a quick
Sometimes the source assembly contains way more types than are sensible to diagram. Types with metadata for validation or mapping for example. Or auto-generated types.
Especially if you want to tailor a diagrammer for a certain target audience and hide away most of the supporting type system to avoid noise and unnecessary questions.

In these scenarios you can supply Regular Expressions for types to `--include` (white-list) and `--exclude` (black-list).
A third option `--report-excluded` will output a `.txt` containing the list of effectively excluded types next to the HTML diagrammer containing the effectively included types.
In these scenarios you can supply Regular Expressions for types to `--generate-diagrammer-include` (white-list) and `--generate-diagrammer-exclude` (black-list).
A third option `--generate-diagrammer-report-excluded` will output a `.txt` containing the list of effectively excluded types next to the HTML diagrammer containing the effectively included types.

<pre>
netAmermaid.exe <b>--include Your\.Models\..+ --exclude .+\+Metadata|.+\.Data\..+Map --report-excluded</b> --assembly ..\path\to\your\assembly.dll --output-folder .
ilspycmd.exe <b>--generate-diagrammer-include Your\.Models\..+ --generate-diagrammer-exclude .+\+Metadata|.+\.Data\..+Map --generate-diagrammer-report-excluded</b> ..\path\to\your\assembly.dll --generate-diagrammer --outputdir .
</pre>

This example
Expand All @@ -179,10 +179,10 @@ This example

### Strip namespaces from XML comments

You can reduce the noise in the member lists of classes on your diagrams by supplying a space-separated list of namespaces to omit from the output like so:
You can reduce the noise in the XML documentation comments on classes on your diagrams by supplying a space-separated list of namespaces to omit from the output like so:

<pre>
netAmermaid.exe <b>--strip-namespaces System.Collections.Generic System</b> --assembly ..\path\to\your\assembly.dll --output-folder .
ilspycmd.exe <b>--generate-diagrammer-strip-namespaces System.Collections.Generic System</b> ..\path\to\your\assembly.dll --generate-diagrammer --output-folder .
</pre>

Note how `System` is replaced **after** other namespaces starting with `System.` to achieve complete removal.
Expand All @@ -193,5 +193,5 @@ Otherwise `System.Collections.Generic` wouldn't match the `Collections.Generic`
If - for whatever reason - you have customized your XML documentation file output name, you can specify a custom path to pick it up from.

<pre>
netAmermaid.exe <b>--docs ..\path\to\your\docs.xml</b> --assembly ..\path\to\your\assembly.dll --output-folder .
ilspycmd.exe <b>--generate-diagrammer-docs ..\path\to\your\docs.xml</b> ..\path\to\your\assembly.dll --generate-diagrammer --output-folder .
</pre>

0 comments on commit 9344123

Please sign in to comment.