Skip to content

Customizing Resources

Stable AspireC4 Reviewed 2026-09-16 purview-dev/aspirec4 architecture architecture-as-code architecture-diagrams aspire aspire-dashboard aspire-dotnet aspire-hosting aspnetcore c4 c4-model developer-experience devex diagram diagrams dotnet likec4 roslyn source-generator visualization

AspireC4 annotates resources in the Aspire app model, so each resource and relationship can be customized before the .c4 file is generated.

Customizes how a resource appears as a node in the diagram:

builder.AddProject<Projects.Api>("api")
.WithLikeC4Details(details =>
details
.WithLabel("Public API")
.WithTechnology(".NET")
.WithDescription("The public HTTP API surface.")
.WithSummary("Handles client requests")
.WithIcon("tech:dotnet")
.WithKind("service")
.WithTag("backend")
.WithLink("https://example.com/docs", "API docs")
.WithMetadata("Owner", "Platform Team")
);
MethodPurpose
WithLabel(string)Display label on the element node.
WithTechnology(string?)Technology string shown beneath the label (e.g. .NET, Redis).
WithDescription(string?)Longer description rendered in the detail panel (Markdown).
WithSummary(string?)One-line summary shown in tooltips/map view.
WithIcon(string?)Icon identifier (e.g. tech:dotnet, azure:storage); null reverts to automatic inference.
WithAutoIcon(bool?)Per-element override for auto-icon inference (null inherits the project setting).
WithKind(string?)Element kind override (e.g. service); must be a valid LikeC4 identifier.
WithTag(string)Adds a tag; a leading # is accepted and stripped.
WithLink(string | Uri, string? title)Adds a hyperlink (absolute, or relative to the .c4 file).
WithMetadata(string key, string value)Adds a metadata key/value pair.

Customizes how the relationship from a resource to a target appears in the diagram. There are two overloads:

// Target is any resource builder.
builder.AddNodeApp("app", ...)
.WithLikeC4Reference(redis, opts => opts.WithLabel("Caches sessions").WithTechnology("Redis Protocol").WithKind("RESP"));
// Target is a resource that exposes a connection string — also calls Aspire's WithReference.
builder.AddProject<Projects.Api>("api")
.WithLikeC4Reference(db, opts => opts.WithLabel("Persists data"), connectionName: "postgres");
MethodPurpose
WithLabel(string)Short label on the relationship arrow.
WithTechnology(string?)Technology/protocol (e.g. HTTP/2, gRPC, AMQP).
WithDescription(string?)Longer relationship description.
WithKind(string?)Typed relationship kind (e.g. async, sync), declared in the specification block and emitted with the configured RelationshipKindSyntax.
WithTag(string)Adds a tag to the relationship.
WithLink(string | Uri, string? title)Adds a hyperlink to the relationship.
WithMetadata(string key, string value)Adds a metadata key/value pair.
WithNavigateTo(string viewId)LikeC4 dynamic view to navigate to when the relationship is clicked.

Attach multiple annotations to the same source — one per target — to customize each relationship independently.

Assigns a resource to a named group. Resources sharing a group are emitted inside a group 'label' { include ... } block in the generated view:

builder.AddRedis("cache").WithLikeC4Group("Platform");
builder.AddRedis("cache").ExcludeFromLikeC4();

The AspireC4 sidecar itself is always excluded from the diagram. Set WithIncludeAspireC4InternalResource(true) in the options callback if you want to inspect it.

By default ParameterResource (passwords/secrets added via AddParameter()/WithParameter()) is excluded. Add or remove types globally:

builder.AddAspireC4(options => options
.WithExcludedResourceType<SomeInternalResource>()
.WithoutExcludedResourceType<ParameterResource>());

A resource is excluded when its runtime type is the same as, or a subclass of, any type in the set.

When AutoIncludeAspireMetadata is All (the default), each element automatically receives aspire-name/aspire-type metadata and links to its allocated HTTP/HTTPS endpoints. Endpoint URLs come from resource snapshots so they use the correct public ports.