In Aspire 13, what is the difference between aspire publish and aspire deploy, and what must the AppHost contain for either to do anything?
answer
- one-way handoff vs Aspire stays in control
- a compute environment adds the steps
- placeholders in publish, values in deploy
- aspire-output by default
- --environment defaults to Production
basics
~20 saspire publish turns the AppHost model into target artifacts — Compose files, Helm charts, Bicep — with secrets left as placeholders; aspire deploy generates, resolves parameters and applies the deployment itself. Both need a compute environment resource, or they do nothing.
solid answer
~50 sBoth commands run the AppHost in a pipeline mode instead of starting the app, and the steps they execute come from resources in the model — chiefly a **compute environment** such as `AddDockerComposeEnvironment`, `AddKubernetesEnvironment` or `AddAzureContainerAppEnvironment`. `aspire publish` is a one-way handoff: it writes artifacts to `aspire-output` (or `-o`) — a `docker-compose.yaml` and an unfilled `.env`, Helm charts, or Bicep — keeping parameters such as secrets unresolved so another tool can supply them. `aspire deploy` keeps Aspire in control: it generates the same kind of output internally, resolves parameter values, builds and pushes images where needed and applies the result — `docker compose up -d --remove-orphans`, a `helm install`, or Azure provisioning. It does not consume earlier published assets. Both run with `--environment Production` unless told otherwise. With no environment resource in the AppHost, either command completes as a no-op.
code
csharp · 13 linesvar builder = DistributedApplication.CreateBuilder(args);
builder.AddDockerComposeEnvironment("compose");
var dbPassword = builder.AddParameter("db-password", secret: true);
var ticketsDb = builder.AddPostgres("postgres", password: dbPassword)
.AddDatabase("ticketsdb");
builder.AddProject<Projects.Ticketing_Api>("ticketing-api")
.WithReference(ticketsDb)
.WithExternalHttpEndpoints();
builder.Build().Run();go deeper
Recall that publish writes deployment files and deploy actually deploys, and that the AppHost needs a target such as AddDockerComposeEnvironment.
Explain the outputs: aspire-output, docker-compose.yaml with an unfilled .env, Helm charts or Bicep, and what deploy adds — parameter resolution, image builds, apply.
Choose between handoff and direct deploy based on who owns the apply step, and guard against the Production default and the multiple-environment binding rule.
Decide whether Aspire's deploy belongs in the delivery pipeline at all or only publishes artifacts into an existing platform's review and release process.
## Deployment is a pipeline the AppHost contributes to In Aspire 13 deployment is **pipeline-based**. The same AppHost that starts the event-ticketing services locally can be run in a pipeline mode, in which resources contribute named **steps** — build images, generate a Compose file, provision Azure resources, apply a Helm chart — and Aspire runs them in dependency order. Three CLI entry points enter that pipeline: | Command | Enters | Purpose | |---|---|---| | `aspire publish` | the publish entry point | emit target-specific artifacts as a one-way handoff, leaving parameters unresolved | | `aspire deploy` | the deploy entry point | generate output, resolve parameters and apply the deployment directly | | `aspire do <step>` | one named step and its dependencies | run a specific step, such as `prepare-compose` | ## Nothing happens without a compute environment A **compute environment** is a resource that represents a deployment target and contributes the steps for compatible compute resources (projects, containers, executables): - `AddDockerComposeEnvironment("compose")` from `Aspire.Hosting.Docker`; - `AddKubernetesEnvironment("k8s")` from `Aspire.Hosting.Kubernetes`; - `AddAzureContainerAppEnvironment("aca")` from `Aspire.Hosting.Azure.AppContainers`, plus App Service and AKS equivalents. If no resource contributes publish or deploy work, the entry point completes as a **no-op**. A team that runs `aspire publish` on a fresh AppHost and gets an empty `aspire-output` has simply not added a target. ## What publish produces `aspire publish` writes to the AppHost directory's `aspire-output` folder unless `-o`/`--output-path` says otherwise. For the ticketing app with a Compose environment that means: - `docker-compose.yaml` with a service per resource, networks and volumes; - `.env` listing the expected parameters **unfilled** — the database password, an API key; - generated Dockerfiles where a resource uses one. It does not build images for Compose; `aspire do prepare-compose --environment staging` builds them and writes a filled `.env.staging`. For Kubernetes, publish emits Helm charts; for Azure targets, Bicep. The point is a reviewable artifact another tool or person applies later. ## What deploy does `aspire deploy` never reads what publish wrote. It: 1. runs the AppHost with the chosen environment (`-e`/`--environment`, default `Production`), so `builder.Environment` branching applies; 2. resolves every parameter — from the AppHost's configuration or an interactive prompt — and caches deployment state per environment in `~/.aspire/deployments/<AppHost hash>/<environment>.json`, which holds prompted values and so deserves the care of a secret; 3. builds container images and, for registries, pushes them; 4. applies the result: for Compose it runs `docker compose up -d --remove-orphans`; for Kubernetes it installs the chart with `helm` against the current `kubectl` context; for Azure Container Apps it provisions the environment, a container registry, managed identity and the apps. `aspire destroy` reverses a deployment after a confirmation prompt, and `aspire deploy --clear-cache` ignores the cached state. ## Choosing between them | Situation | Command | |---|---| | a platform team reviews and applies manifests in its own CD system | `aspire publish`, commit or hand over the artifacts | | one service team deploys straight to a Compose host or Azure | `aspire deploy` | | CI should build images now and deploy later | `aspire do` with the relevant `prepare-*` or build step | The rule of thumb: publish when someone else owns the apply step, deploy when Aspire may own it. ## Common misunderstandings - Expecting `aspire publish` to push images or touch a server — it only writes files. - Running `aspire deploy` after hand-editing the published `docker-compose.yaml` and expecting the edits to survive — deploy regenerates its own output; customise through the AppHost (`PublishAsDockerComposeService`, `ConfigureComposeFile`) instead. - Forgetting `--environment`: both commands default to `Production`, so a staging deploy that omits it resolves production parameters.
- Why does aspire publish leave the database password empty in the .env file?Publish is a one-way handoff that preserves parameter requirements rather than values, so secrets never land in generated artifacts. The `.env` lists the expected variables unfilled; whoever applies the artifacts supplies them, or `aspire do prepare-compose --environment <name>` writes a filled `.env.<name>` for a specific environment.
- You add both a Compose and an Azure Container Apps environment. What does publish require?With more than one compute environment there is no default, so every compute resource must be bound with `WithComputeEnvironment(...)`. Otherwise the pipeline fails with an `InvalidOperationException` naming the unassigned resources and the environments it found.
- aspire publish builds and pushes the container images for the Compose target.
- aspire deploy applies the artifacts that aspire publish wrote earlier.
- Publish and deploy work on any AppHost without a compute environment resource.
- Published artifacts contain the resolved secret values so they are ready to run.
- Both commands default to the Development environment, like aspire run.
Assumes Aspire 13.6: the pipeline-based publish, deploy and aspire do commands replaced 9.x publishing callbacks in 13.0, and the docs still badge aspire publish as Preview.