Skip to content

CLI Tool

github-actions[bot] edited this page Nov 30, 2026 · 10 revisions

CLI Tool (dotnet fe)

Install Ferrous.Tool as a global or local .NET tool:

dotnet tool install -g Ferrous.Tool

Typical Workflow

  1. Bootstrap Rust-strict settings in a repo:

    dotnet fe init --strict

    Generates .editorconfig entries for all FE0001–FE0502 rules (elevating warnings to error when --strict is passed) and is idempotent on re-runs.

  2. Enforce build, supply-chain & NativeAOT hygiene in CI:

    dotnet fe audit . --packages --allow-licenses MIT --lockfile --semver --aot --cve

    Verifies <Nullable>enable</Nullable>, <TreatWarningsAsErrors>true</TreatWarningsAsErrors>, <AnalysisLevel>, pinned package versions, SPDX license allowlists, packages.lock.json, <EnablePackageValidation>true</EnablePackageValidation>, NativeAOT/trimming readiness, and dotnet list package --vulnerable --deprecated.

  3. Build a zero-config, searchable API docs site (like cargo doc):

    dotnet fe doc ./src --output ./docs-site --title "My API Reference" --logo ./assets/icon.png --open

    Generates a static HTML site directly from Roslyn syntax trees and /// XML doc comments—no DocFX config needed. Includes:

    • Roslyn-powered zero-JS C# syntax highlighting (SyntaxFactory.ParseTokens)
    • Full XML doc rendering (<summary>, <remarks>, <typeparam>, <param>, <returns>, <exception>, <value>, <example><code>), clickable cross-page <see cref="..."/> links, and <inheritdoc /> resolution from base types/interfaces
    • Ferrous attribute badges, [DiscriminatedUnion] variant tables, [Newtype] wrapper cards, and embedded Mermaid [Typestate] graphs
    • Collapsible left-hand namespace/type outline sidebar, mobile slide-over drawer, client-side instant search (/), system-aware light/dark theme toggle, content-fingerprinted CSS/JS filenames, and --watch live-rebuild mode

    See Ferrous's own dogfooded site at https://ferrous.westness.cc/api/.

  4. Run executable doc-tests & unit tests together (like cargo test):

    dotnet fe doctest ./src
    dotnet fe test .

    Extracts, compiles, and runs /// <example><code> XML doc blocks and fenced ```csharp Markdown blocks (supporting no_run, ignore, compile_fail, and compile_fail(FE0200)).

  5. Generate & verify typestate diagrams:

    dotnet fe graph src/ --format mermaid --write README.md

    Scans [Typestate] (IsInitial, IsTerminal) and [ConsumesSelf] declarations, emits a Mermaid stateDiagram-v2, optionally updates Markdown files in-place, and warns about unreachable or non-terminal dead-end states.

  6. Inspect generated union & newtype code (like cargo expand):

    dotnet fe expand src/PaymentEvent.cs --type PaymentEvent

    Runs Ferrous.Unions directly on your C# files and prints the exact .g.cs output to stdout.


Command Reference

Command Description
dotnet fe expand <path> [--type <Name>] Expand [DiscriminatedUnion] and [Newtype] source-generator output (including generated System.Text.Json converters) to stdout.
dotnet fe graph <path> [--format mermaid|text] [--write <file>] Render [Typestate] state diagrams (including IsInitial and IsTerminal), optionally write them into Markdown docs between markers, and detect unreachable or dead-end states.
dotnet fe init [dir] [--strict] Write FE0001–FE0503 .editorconfig rules (--strict elevates warnings to error).
dotnet fe audit [dir] [--packages] [--allow-licenses <SPDX,...>] [--lockfile] [--semver] [--aot] [--cve] Audit .csproj / Directory.Build.props for Rust-strict build hygiene, pinned package versions, SPDX license allowlists, lockfiles, SemVer validation, NativeAOT readiness, and NuGet CVEs.
dotnet fe doctest [path] [--no-md] Extract, compile, and run /// <example><code> XML doc blocks and fenced ```csharp Markdown doc-tests (no_run, ignore, compile_fail(FE...)).
dotnet fe test [path] [--no-dotnet-test] [--no-doctest] Run dotnet test and dotnet fe doctest together in a single command.
dotnet fe doc [path] [--output <dir>] [--title <name>] [--logo <file>] [--watch] [--open] Generate a searchable static HTML API docs site with Roslyn syntax highlighting, full XML doc rendering, cross-page <see cref> links, <inheritdoc />, outline sidebar, theme switcher, Mermaid [Typestate] graphs, and --watch mode.

| dotnet fe migrate [path] [--report \| --apply] | Scan a C# codebase for progressive Ferrous migration opportunities (async void, nullable returns, throwing methods, raw lock, mutable static) and optionally apply safe mechanical upgrades. |

IDE Migration Refactorings (Ferrous.CodeFixes)

In addition to diagnostic quick-fixes, Ferrous.CodeFixes includes on-demand Roslyn Ctrl+. refactorings (supported in Visual Studio, VS Code C# Dev Kit, and JetBrains Rider) for migrating existing code method-by-method:

  • Convert throwing method (sync or async Task<T>) → Result<T, string> (rewrites return type, return, and throw statements)
  • Convert nullable-returning method (T?, async Task<T?>, or expression-bodied) → Option<T> (rewrites return null; → Option.None<T>(), return value; → Option.Some(value), or Option.FromNullable(...))
  • Wrap primitive parameter in [Newtype(typeof(T))] (generates the readonly partial struct declaration and updates the parameter)
  • Convert abstract record hierarchy → [DiscriminatedUnion] (collapses base + derived records into a zero-boxing union struct)
  • Convert lock (_gate) + protected field → Mutex<T> (removes the lock object, wraps the field in Mutex<T>, and rewrites lock blocks to using (var guard = _field.Lock()))

Clone this wiki locally