AspireC4.Hosting 17.0.0-prerelease.3

This is a prerelease version of AspireC4.Hosting.
There is a newer version of this package available.
See the version list below for details.
dotnet add package AspireC4.Hosting --version 17.0.0-prerelease.3
                    
NuGet\Install-Package AspireC4.Hosting -Version 17.0.0-prerelease.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AspireC4.Hosting" Version="17.0.0-prerelease.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AspireC4.Hosting" Version="17.0.0-prerelease.3" />
                    
Directory.Packages.props
<PackageReference Include="AspireC4.Hosting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AspireC4.Hosting --version 17.0.0-prerelease.3
                    
#r "nuget: AspireC4.Hosting, 17.0.0-prerelease.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AspireC4.Hosting@17.0.0-prerelease.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AspireC4.Hosting&version=17.0.0-prerelease.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=AspireC4.Hosting&version=17.0.0-prerelease.3&prerelease
                    
Install as a Cake Tool

AspireC4.Hosting

NuGet version

An Aspire integration that generates a live LikeC4 architecture diagram from your AppHost's resource graph, and hosts it in the Aspire dashboard.

Prerequisites

  • The .NET 11 SDK to build the AppHost. The package's source generator runs inside the compiler and is built against Roslyn 5.9; an older SDK reports CS9057 and skips it, which drops the ASPIREC4xxx validation and the [LikeC4Registry] types.
  • A net10.0 or net11.0 AppHost. This package ships both assets; an AppHost targeting net10.0 (the Aspire AppHost framework) resolves the net10.0 one. .NET 8 and .NET 9 are not supported.
  • Aspire 13.6.5 or later, on the 13 line (an Aspire.AppHost.Sdk AppHost) or 17 and later (a Microsoft.NET.Sdk AppHost referencing Aspire.Hosting.AppHost). One package serves both.
  • Docker (or Podman) for the default LikeC4 sidecar container.
  • Optional: a local Node.js CLI runtime (npx, pnpm, yarn, bun or deno) if you call .WithLocalCLI() instead.

The requirements page has the detail behind each of these.

Container image exports verify bind sharing through Purview.Containers.Environment, using alpine:3.19 by default. Offline environments must preload the probe image or set CONTAINER_ENVIRONMENT_PROBE_IMAGE. For a daemon inside WSL or a shared remote filesystem, also install Purview.Containers.Aspire and call builder.AddContainerEnvironment() to adapt the live sidecar's mounts. See the container environment guide for verified path mappings, write permissions and remote-host limitations.

Installation

Add the package to the AppHost project:

dotnet add package AspireC4.Hosting
<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <PackageReference Include="Aspire.Hosting.AppHost" />
    <PackageReference Include="AspireC4.Hosting" />
  </ItemGroup>
</Project>

Quick start

var builder = DistributedApplication.CreateBuilder(args);

builder.AddAspireC4();

builder.AddProject<Projects.Api>("api");

builder.Build().Run();

When the AppHost starts, this writes ./.aspirec4/likec4/model.gen.c4 and starts the LikeC4 server. The diagram refreshes as the Aspire app changes. Open it from the aspirec4 resource in the dashboard.

Screenshots

AspireC4 architecture diagram of the sample AppHost: a Node app referencing Redis Commander, local Redis and Postgres in a local dev group, PgWeb, Azure Redis and Azure Postgres, with labelled relationships

The image above is captured from the sample AppHost in the repository and stored in docs/images/screenshots/. Your own diagram exports a PNG for every view to ./.aspirec4/images/ on startup (ExportImages), which is the easiest way to capture one.

Configuration

Configure the diagram in the configure callback, or through the AspireC4 configuration section.

builder.AddAspireC4(configure: options => options
    .WithTitle("Orders platform")
    .WithViewTitle("Architecture")
    .WithHideFromDashboard());
Property Default Description
Title null Title shown in the LikeC4 app
ViewTitle "Architecture" Title of the generated view
ViewDescription null Optional view description
OutputDirectory "./.aspirec4/likec4/" Where the generated .c4 file is written
ProjectDirectory null An existing LikeC4 project to generate into and serve
FileName "model.gen" Generated file name without extension
DisableHMR false Disable Hot Module Replacement
HMRPort null Fixed HMR port. Allocated dynamically by default
ContainerImageTag null (latest) Pin the ghcr.io/likec4/likec4 image tag
AutoIconsEnabled true Recognise each resource's technology and icon from its framework (including a .NET project's flavour), Aspire type or container image, and fuzzy-match the rest. See Technology and icons
TechnologyOverrides [] App-wide rules that name the technology and icon by package, resource type or container image, before the built-in catalogue: WithPackageTechnology, WithResourceTypeTechnology, WithContainerImageTechnology. See Overriding it
HideFromDashboard false Hide the LikeC4 sidecar from the dashboard
IncludeAspireDashboardLinks true Link diagram elements back to the Aspire dashboard
ExportImages true Export every view as an image to ./.aspirec4/images/ when the model changes
ImageFormats {Png} Png and/or Jpg
UseLegacyLayout false Restore the original output paths and dashboard names
ExtensionsDirectory "./likec4-extensions" Hand-written .c4 files beside the AppHost, included automatically when the folder exists
GenerateGitIgnoreFile true Write .gitignore files that keep the generated model out of git

Run LikeC4 locally instead of in a container

builder.AddAspireC4().WithLocalCLI();

Source control and your own LikeC4 files

Add nothing to .gitignore: AspireC4 writes its own beside the generated files, naming only what it writes, and never replaces one it did not write. The exported images stay visible to git so they can be committed. Files are written only when their content changes, so restarting an unchanged application touches nothing.

Hand-written .c4 files — people, external systems, extend blocks for generated elements, extra views — go in a likec4-extensions/ folder beside the AppHost, which is included automatically. See Source control and Extending the generated model.

Use your own LikeC4 project

Serve a LikeC4 project you already maintain. The generated model is added to it as one more file, and your likec4.config.json, .c4 sources and views are left alone.

builder.AddAspireC4(configure: options => options
    .WithLikeC4ProjectFolder("../../architecture"));

builder.AddProject<Projects.Api>("api")
       .WithLikeC4Element("cloud.backend.api");   // attach live state to an element you declared

Describing resources

var db = builder.AddPostgres("pg").AddDatabase("orders");

builder.AddProject<Projects.Api>("api")
    .WithLikeC4Details(details => details
        .WithLabel("Public API")
        .WithTechnology(".NET")
        .WithDescription("The public HTTP API surface.")
        .WithIcon("tech:dotnet")
        .WithTag("backend"))
    .WithLikeC4ConnectionReference(db, opts => opts.WithLabel("Persists orders"))   // also calls WithReference
    .WithLikeC4Group("Platform");

builder.AddContainer("debug-tools", "busybox")
    .ExcludeFromLikeC4();

Each element also records where it comes from, with no code: a local .NET, Node, Bun, Python or Go project gets its project-path (relative to the AppHost) and its runtime version, and a container gets its full container-image reference and tag. See where each resource comes from.

Compile-time validation

The package includes a source generator that checks the values passed to .WithTag(), .WithKind(), .WithLikeC4Group() and .WithMetadata() against a registry class in your AppHost. You do not need to reference anything else.

using Aspire.Hosting.AspireC4;

[LikeC4Registry(Strict = LikeC4Severity.Warning)]
internal static class ArchitectureRegistry
{
    public static class Tags
    {
        public const string Backend = "backend";
    }

    public static class Groups
    {
        public const string Platform = "Platform";
    }
}

Set the project-wide severity with <AspireC4Strict>warning</AspireC4Strict>, and add your .c4 files as <AdditionalFiles> to validate against their specification blocks too. The diagnostics are ASPIREC4001 to ASPIREC4007.

TypeScript AppHosts

The same API is exported to TypeScript AppHosts in camel case (addAspireC4, withLikeC4Details, …). Add "AspireC4.Hosting" to the packages in aspire.config.json and run aspire restore.

ER diagrams from Entity Framework Core

Add AspireC4.Hosting.EntityFrameworkCore to the AppHost and call .WithEntityFrameworkDiagram() to add a live ER diagram of your DbContext types, linked from the architecture diagram.

It is additive, and optional: AddAspireC4() stays exactly as it is, and WithEntityFrameworkDiagram() is an extension on the builder it returns, so the two diagrams run side by side — or you keep the architecture diagram on its own and never install the package. The ER diagram has its own renderers (Interactive by default, plus Mermaid, Dbml and D2) and options; see that package's README.

More information

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AspireC4.Hosting:

Package Downloads
AspireC4.Hosting.EntityFrameworkCore

Aspire hosting extension for AspireC4, generating a live d2lang ER diagram from Entity Framework Core DbContext types.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
17.0.0 145 11/26/2026
17.0.0-prerelease.4 108 11/22/2026
17.0.0-prerelease.3 80 11/21/2026
17.0.0-prerelease.2 104 11/20/2026
17.0.0-prerelease.1 120 11/19/2026
13.6.5 402 11/16/2026
13.6.5-preview.1 96 11/12/2026
13.6.4-preview.3 81 11/8/2026
13.6.4-preview.2 124 10/31/2026
13.6.4-preview.1 93 10/29/2026
13.6.0-preview.4 82 10/27/2026
13.6.0-preview.3 102 10/24/2026
13.6.0-preview.2 110 10/22/2026
13.6.0-preview.1 100 10/18/2026
13.5.3.11 425 10/7/2026
13.5.3.10 118 9/29/2026
13.5.3.9 127 9/29/2026
13.5.3.8 131 9/28/2026
13.5.3.7 127 9/27/2026
13.5.3.6 129 9/25/2026
Loading failed