{"record":{"id":"c6c3fbbdb76d5512","repo":"microsoft/aspire","slug":"resource-r-name-is-configured-to-publish-as-an-azure","errorCode":null,"errorMessage":"Resource '{r.Name}' is configured to publish as an Azure Container App, but there are no 'AzureContainerAppEnvironmentResource' resources. Ensure you have added one by calling 'AddAzureContainerAppEnvironment'.","messagePattern":"Resource '(.+?)' is configured to publish as an Azure Container App, but there are no 'AzureContainerAppEnvironmentResource' resources\\. Ensure you have added one by calling 'AddAzureContainerAppEnvironment'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs","lineNumber":87,"sourceCode":"                action: ctx =>\n                {\n                    if (!ctx.ExecutionContext.IsPublishMode)\n                    {\n                        return Task.CompletedTask;\n                    }\n\n                    var environments = ctx.Model.Resources\n                        .OfType<AzureContainerAppEnvironmentResource>()\n                        .Where(environment => !environment.IsExcludedFromPublish())\n                        .ToList();\n                    if (environments.Count == 0)\n                    {\n                        foreach (var r in ctx.Model.GetComputeResources())\n                        {\n                            if (r.HasAnnotationOfType<AzureContainerAppCustomizationAnnotation>() ||\n                                r.HasAnnotationOfType<AzureContainerAppJobCustomizationAnnotation>())\n                            {\n                                throw new InvalidOperationException($\"Resource '{r.Name}' is configured to publish as an Azure Container App, but there are no '{nameof(AzureContainerAppEnvironmentResource)}' resources. Ensure you have added one by calling '{nameof(AddAzureContainerAppEnvironment)}'.\");\n                            }\n                        }\n                    }\n                    else\n                    {\n                        // Name resolvers run while each environment's Bicep module is generated. Force evaluation\n                        // here so the shared tracker sees every legacy fallback before deployment targets are prepared.\n                        foreach (var environment in environments)\n                        {\n                            _ = environment.GetBicepTemplateString();\n                        }\n\n                        marker.ValidateManagedEnvironmentNames(\n                            environments.Select(environment => environment.Name).ToHashSet(StringComparer.Ordinal));\n                    }\n\n                    return Task.CompletedTask;\n                },","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs#L69-L105","documentation":"During publish orchestration, resources carrying AzureContainerAppCustomizationAnnotation or AzureContainerAppJobCustomizationAnnotation are meant to be published as Azure Container Apps, which requires at least one AzureContainerAppEnvironmentResource in the model. If none exists when the infrastructure is built, this DistributedApplicationException is thrown, naming the offending resource and the missing AddAzureContainerAppEnvironment call.","triggerScenarios":"Calling .PublishAsAzureContainerApp()-style APIs or applying Container App customizations/annotations to a compute resource without ever calling builder.AddAzureContainerAppEnvironment(...) before publishing.","commonSituations":"Porting an AppHost from another deployment target (e.g. ACA via azd manually) to Aspire's Container App publishing and forgetting the environment declaration; conditional environment setup that didn't run; template samples with Container App customizations run through publish.","solutions":["Add builder.AddAzureContainerAppEnvironment(\"aca-env\") in the AppHost before building/publishing","Remove Container App customizations (PublishAsAzureContainerApp / related annotations) from resources that shouldn't target Container Apps","Verify the environment addition is not gated behind a flag or condition that skips it in your publish run"],"exampleFix":"// before\nvar api = builder.AddProject<Projects.Api>(\"api\")\n    .PublishAsAzureContainerApp(...);\n// after\nbuilder.AddAzureContainerAppEnvironment(\"aca-env\");\nvar api = builder.AddProject<Projects.Api>(\"api\")\n    .PublishAsAzureContainerApp(...);","handlingStrategy":"validation","validationCode":"if (!builder.Resources.OfType<AzureContainerAppEnvironmentResource>().Any() &&\n    builder.Resources.Any(r => r.HasAnnotationOfType<AzureContainerAppCustomizationAnnotation>()))\n{\n    throw new InvalidOperationException(\"Add AddAzureContainerAppEnvironment before Container App customizations\");\n}","typeGuard":null,"tryCatchPattern":"try { await PublishAsync(model); }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"AddAzureContainerAppEnvironment\"))\n{\n    logger.LogError(ex, \"A Container App environment is required\");\n}","preventionTips":["Always declare AddAzureContainerAppEnvironment when targeting Container Apps","Keep environment setup unconditional and early in the AppHost","Audit annotations/PublishAsAzureContainerApp usage against available environments"],"tags":["azure","container-apps","publish","missing-environment"],"backgroundTag":"missing-dependency","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}