microsoft/aspire · error · DistributedApplicationException
The Rust app ' ' targets ' ', which requires container…
Error message
The Rust app '{resource.Name}' targets '{cargoTarget}', which requires container target platform '{platform}', but WithContainerBuildOptions selected '{configuredPlatform}'. What it means
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.
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.
Example fix
// before .WithContainerBuildOptions(ctx => ctx.TargetPlatform = "linux/amd64") // conflicts with linux/arm64 target // after // remove the override; the Rust pipeline sets ctx.TargetPlatform = "linux/arm64"
Defensive patterns
Strategy: validation
Validate before calling
var requiredPlatform = GetRequiredPlatformForCargoTarget(cargoTarget); // e.g. linux/arm64
if (configuredTargetPlatform is { } p && p != requiredPlatform)
throw new InvalidOperationException($"TargetPlatform '{p}' conflicts with required '{requiredPlatform}'"); Try / catch
try { PublishAsync(); }
catch (DistributedApplicationException ex) when (ex.Message.Contains("container target platform")) {
logger.LogError("Remove or align the WithContainerBuildOptions TargetPlatform override");
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- The Rust app ' ' targets ' ', which cannot be mapped to a…
- The Rust app ' ' targets ' ', which is not compatible with…
- Container runtime ' ' is not running or is unhealthy.
- Java application ' ' cannot be published because its…
- The published Rust app
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/c21245cad305d6f4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Rust/RustHostingExtensions.cs:799
dockerfile.BuildSecrets[buildSecret.Key] = buildSecret.Value;
}
dockerfile.ImageName = provisionalDockerfile.ImageName ?? dockerfile.ImageName;
dockerfile.ImageTag = provisionalDockerfile.ImageTag ?? dockerfile.ImageTag;
dockerfile.HasEntrypoint = provisionalDockerfile.HasEntrypoint;
dockerfile.BuildContextIgnoreContent = provisionalDockerfile.BuildContextIgnoreContent;
if (targetPlatform is { } platform)
{
var cargoTarget = resource.TryGetLastAnnotation<RustCargoOptionsAnnotation>(out var options)
? options.Target
: null;
containerBuilder.WithContainerBuildOptions(context =>
{
if (context.TargetPlatform is { } configuredPlatform && configuredPlatform != platform)
{
throw new DistributedApplicationException(
$"The Rust app '{resource.Name}' targets '{cargoTarget}', " +
$"which requires container target platform '{platform}', but WithContainerBuildOptions selected '{configuredPlatform}'.");
}
// The earlier Rust callback establishes the mapped default before caller callbacks run.
// Reapply it here only after confirming a later callback did not choose a conflicting platform.
context.TargetPlatform = platform;
});
}
}
private static DockerfileBuildAnnotation CreateGeneratedDockerfileAnnotation(
IDistributedApplicationBuilder applicationBuilder,
RustAppResource resource,
string workingDirectory,
string? stage)
{
// Replacing the integration-owned provisional annotation directly avoids rerunning WithDockerfileFactory,View on GitHub (pinned to 25830f84bd)