{"record":{"id":"b86f61033984bfe1","repo":"microsoft/aspire","slug":"resource-r-name-is-configured-to-publish-as-a-docker-compose","errorCode":null,"errorMessage":"Resource '{r.Name}' is configured to publish as a Docker Compose service, but there are no 'DockerComposeEnvironmentResource' resources. Ensure you have added one by calling 'AddDockerComposeEnvironment'.","messagePattern":"Resource '(.+?)' is configured to publish as a Docker Compose service, but there are no 'DockerComposeEnvironmentResource' resources\\. Ensure you have added one by calling 'AddDockerComposeEnvironment'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Docker/DockerComposeEnvironmentExtensions.cs","lineNumber":48,"sourceCode":"        {\n            builder.Services.AddSingleton<DockerComposePipelineStepMarker>();\n\n            builder.Pipeline.AddStep(\n                name: DockerComposePipelineStepMarker.StepName,\n                action: ctx =>\n                {\n                    if (!ctx.ExecutionContext.IsPublishMode)\n                    {\n                        return Task.CompletedTask;\n                    }\n\n                    if (!ctx.Model.Resources.OfType<DockerComposeEnvironmentResource>().Any())\n                    {\n                        foreach (var r in ctx.Model.GetComputeResources())\n                        {\n                            if (r.HasAnnotationOfType<DockerComposeServiceCustomizationAnnotation>())\n                            {\n                                throw new InvalidOperationException($\"Resource '{r.Name}' is configured to publish as a Docker Compose service, but there are no '{nameof(DockerComposeEnvironmentResource)}' resources. Ensure you have added one by calling '{nameof(AddDockerComposeEnvironment)}'.\");\n                            }\n                        }\n                    }\n\n                    return Task.CompletedTask;\n                },\n                requiredBy: WellKnownPipelineSteps.BeforeStart);\n        }\n\n        return builder;\n    }\n\n    private sealed class DockerComposePipelineStepMarker\n    {\n        public const string StepName = \"validate-docker-compose\";\n    }\n\n    /// <summary>","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Docker/DockerComposeEnvironmentExtensions.cs#L30-L66","documentation":"During publish, this infrastructure callback verifies that any compute resource carrying a DockerComposeServiceCustomizationAnnotation actually has a DockerComposeEnvironmentResource in the model. If none exists, the customization cannot be applied and an InvalidOperationException is thrown naming the offending resource. It catches compose customizations applied without ever adding the compose environment.","triggerScenarios":"Calling WithDockerComposeServiceCustomization (or similar compose-specific APIs) on a resource while the builder never invoked AddDockerComposeEnvironment, then running publish.","commonSituations":"Copy-pasting code that customizes compose output but omitting the environment setup line; refactoring that removed the AddDockerComposeEnvironment call while leaving customizations; sharing a host module where only one side of the setup was included.","solutions":["Add a Docker Compose environment before publishing: builder.AddDockerComposeEnvironment(\"env\").","Or remove the compose customization call from the resource if compose publishing is not intended.","Verify ordering — the environment must be added to the same builder/model being published."],"exampleFix":"// before\nbuilder.AddProject<Projects.Api>(\"api\").WithDockerComposeServiceCustomization(c => { });\n// (no environment)\n// after\nbuilder.AddDockerComposeEnvironment(\"compose-env\");\nbuilder.AddProject<Projects.Api>(\"api\").WithDockerComposeServiceCustomization(c => { });","handlingStrategy":"validation","validationCode":"// before publish, verify the environment exists if compose customizations are used\nif (model.Resources.OfType<DockerComposeEnvironmentResource>().Any() == false &&\n    model.Resources.Any(r => r.HasAnnotationOfType<DockerComposeServiceCustomizationAnnotation>()))\n    throw new InvalidOperationException(\"AddDockerComposeEnvironment must be called before using compose customizations\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call AddDockerComposeEnvironment at the top of the AppHost when targeting compose","Keep environment setup and compose customizations in the same builder configuration","Review removed lines during refactors that may have dropped the environment registration"],"tags":["docker-compose","environment","publish","misconfiguration"],"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"}