{"record":{"id":"c21245cad305d6f4","repo":"microsoft/aspire","slug":"the-rust-app-resource-name-targets-cargotarget-which","errorCode":null,"errorMessage":"The Rust app '{resource.Name}' targets '{cargoTarget}', which requires container target platform '{platform}', but WithContainerBuildOptions selected '{configuredPlatform}'.","messagePattern":"The Rust app '(.+?)' targets '(.+?)', which requires container target platform '(.+?)', but WithContainerBuildOptions selected '(.+?)'\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Rust/RustHostingExtensions.cs","lineNumber":799,"sourceCode":"            dockerfile.BuildSecrets[buildSecret.Key] = buildSecret.Value;\n        }\n\n        dockerfile.ImageName = provisionalDockerfile.ImageName ?? dockerfile.ImageName;\n        dockerfile.ImageTag = provisionalDockerfile.ImageTag ?? dockerfile.ImageTag;\n        dockerfile.HasEntrypoint = provisionalDockerfile.HasEntrypoint;\n        dockerfile.BuildContextIgnoreContent = provisionalDockerfile.BuildContextIgnoreContent;\n\n        if (targetPlatform is { } platform)\n        {\n            var cargoTarget = resource.TryGetLastAnnotation<RustCargoOptionsAnnotation>(out var options)\n                ? options.Target\n                : null;\n\n            containerBuilder.WithContainerBuildOptions(context =>\n            {\n                if (context.TargetPlatform is { } configuredPlatform && configuredPlatform != platform)\n                {\n                    throw new DistributedApplicationException(\n                        $\"The Rust app '{resource.Name}' targets '{cargoTarget}', \" +\n                        $\"which requires container target platform '{platform}', but WithContainerBuildOptions selected '{configuredPlatform}'.\");\n                }\n\n                // The earlier Rust callback establishes the mapped default before caller callbacks run.\n                // Reapply it here only after confirming a later callback did not choose a conflicting platform.\n                context.TargetPlatform = platform;\n            });\n        }\n    }\n\n    private static DockerfileBuildAnnotation CreateGeneratedDockerfileAnnotation(\n        IDistributedApplicationBuilder applicationBuilder,\n        RustAppResource resource,\n        string workingDirectory,\n        string? stage)\n    {\n        // Replacing the integration-owned provisional annotation directly avoids rerunning WithDockerfileFactory,","sourceCodeStart":781,"sourceCodeEnd":817,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Rust/RustHostingExtensions.cs#L781-L817","documentation":"For a Rust target that requires a specific container platform (the cargoTarget's mapped triple), the publish pipeline validates that no caller-supplied WithContainerBuildOptions callback selected a different TargetPlatform. If a conflicting platform was configured, this DistributedApplicationException names both the required and the configured platform.","triggerScenarios":"Calling .WithContainerBuildOptions(ctx => ctx.TargetPlatform = ...) with a platform different from the one required by the Rust target (e.g. a windows/amd64 platform while the cargo target demands linux/arm64) before publishing.","commonSituations":"Copying container build options from another project; targeting multi-arch builds without realizing a Rust cross-compile target pins the platform; stale build options left after changing the cargo target.","solutions":["Remove the conflicting WithContainerBuildOptions TargetPlatform setting and let the Rust pipeline select the required platform.","Change the platform to the one required by the cargo target, as stated in the message.","Change the cargo target to one compatible with your desired platform.","Reorder callbacks so the Rust default is applied after caller options only when there is no conflict — check all WithContainerBuildOptions registrations."],"exampleFix":"// before\n.WithContainerBuildOptions(ctx => ctx.TargetPlatform = \"linux/amd64\") // conflicts with linux/arm64 target\n// after\n// remove the override; the Rust pipeline sets ctx.TargetPlatform = \"linux/arm64\"","handlingStrategy":"validation","validationCode":"var requiredPlatform = GetRequiredPlatformForCargoTarget(cargoTarget); // e.g. linux/arm64\nif (configuredTargetPlatform is { } p && p != requiredPlatform)\n    throw new InvalidOperationException($\"TargetPlatform '{p}' conflicts with required '{requiredPlatform}'\");","typeGuard":null,"tryCatchPattern":"try { PublishAsync(); }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"container target platform\")) {\n    logger.LogError(\"Remove or align the WithContainerBuildOptions TargetPlatform override\");\n}","preventionTips":["Do not set TargetPlatform for Rust resources with pinned cargo targets","Update WithContainerBuildOptions whenever the cargo target changes","Search the AppHost for all WithContainerBuildOptions registrations before adding new ones"],"tags":["publish","docker","platform","rust"],"backgroundTag":"conflicting-config-options","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"}