Skip to content

Resource Publishing

Aspire provides a flexible mechanism for publishing resource manifests, enabling seamless integration with various deployment environments. Resources are serialized into JSON format, which can be consumed by deployment tools.

Custom resources that publish JSON manifest entries must:

  1. Register a callback using ManifestPublishingCallbackAnnotation in the constructor.
  2. Implement the callback to write JSON via ManifestPublishingContext.Writer.
  3. Use value objects (IManifestExpressionProvider) for structured fields.

Resources can opt-out of being included in the publishing manifest entirely by calling the ExcludeFromManifest() extension method on the IResourceBuilder<T>. Resources marked this way will be omitted when generating publishing assets like Docker Compose files or Kubernetes manifests.

Consider the following example of a custom Azure Bicep resource that publishes its parameters to a manifest:

C# — AzureBicepResource.cs
public class AzureBicepResource : Resource, IAzureResource
{
public AzureBicepResource(string name, ...) : base(name)
{
Annotations.Add(new ManifestPublishingCallbackAnnotation(WriteToManifest));
}
}

As an example, the WriteToManifest method serializes the resource’s parameters into a JSON object. This method is invoked during the manifest publishing phase:

public virtual void WriteToManifest(ManifestPublishingContext context)
{
context.Writer.WriteString("type", "azure.bicep.v0");
context.Writer.WriteString("path", context.GetManifestRelativePath(path));
context.Writer.WriteStartObject("params");
foreach (var kv in Parameters)
{
context.Writer.WritePropertyName(kv.Key);
var v = kv.Value is IManifestExpressionProvider p ? p.ValueExpression : kv.Value?.ToString();
context.Writer.WriteString(kv.Key, v ?? "");
context.TryAddDependentResources(kv.Value);
}
context.Writer.WriteEndObject();
}

The following table summarizes the key steps and conventions for publishing resources:

StepAPI / CallPurpose
Register callbackAnnotations.Add(new ManifestPublishingCallbackAnnotation(WriteToManifest))Hook custom JSON writer
Implement WriteToManifestUse context.Writer to emit JSON propertiesDefine resource manifest representation
Structured fieldsIManifestExpressionProvider.ValueExpressionEnsure publish-time placeholders are preserved
ConventionRationale
Data-only resource classesSeparates data model from behavior
*BuilderExtensions classesGroups all API methods per integration
Public annotationsAllow dynamic runtime addition/removal
[ResourceName] attributeEnforces valid resource naming at compile time
Preserve parameter/value objectsEnsures deferred evaluation of secrets/outputs
Ask & Answer Collaborate Community Discuss Watch