{"record":{"id":"5121c080d6e0e566","repo":"microsoft/aspire","slug":"unable-to-work-out-which-binary-the-rust-app-resourcename","errorCode":null,"errorMessage":"Unable to work out which binary the Rust app '{resourceName}' produces: the package '{package.Name}' declares no binary targets. Point the app directory at a package with a binary, or select one with WithCargoPackage(\"<name>\").","messagePattern":"Unable to work out which binary the Rust app '(.+?)' produces: the package '(.+?)' declares no binary targets\\. Point the app directory at a package with a binary, or select one with WithCargoPackage\\(\"<name>\"\\)\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Rust/RustCargoTargetResolver.cs","lineNumber":150,"sourceCode":"            _ => profile\n        };\n    }\n\n    private static string ResolveBinaryName(CargoMetadata metadata, string? requestedPackage, string resourceName)\n    {\n        var package = ResolvePackage(metadata, requestedPackage, resourceName);\n\n        if (package.DefaultRun is { Length: > 0 } defaultRun)\n        {\n            return defaultRun;\n        }\n\n        return package.BinTargetNames switch\n        {\n            [var single] => single,\n            // A package with no binary at all is a different mistake from an ambiguous one, and pointing the\n            // user at WithCargoBinTarget would send them looking for a target that does not exist.\n            [] => throw new DistributedApplicationException(\n                $\"Unable to work out which binary the Rust app '{resourceName}' produces: the package '{package.Name}' declares no \" +\n                $\"binary targets. Point the app directory at a package with a binary, or select one with WithCargoPackage(\\\"<name>\\\").\"),\n            var many => throw new DistributedApplicationException(\n                $\"Unable to work out which binary the Rust app '{resourceName}' produces: the package '{package.Name}' declares \" +\n                $\"{many.Count} binary targets. Call WithCargoBinTarget(\\\"<name>\\\") to select one.\")\n        };\n    }\n\n    private static CargoPackage ResolvePackage(CargoMetadata metadata, string? requestedPackage, string resourceName)\n    {\n        if (requestedPackage is not null)\n        {\n            // Reported here rather than left to cargo because this runs before any build: the debugger needs\n            // the executable path up front, so a typo would otherwise surface as an unexplained\n            // \"Sequence contains no matching element\" from LINQ.\n            return metadata.Packages.FirstOrDefault(p => p.Name == requestedPackage)\n                ?? throw new DistributedApplicationException(\n                    $\"The Rust app '{resourceName}' requested the cargo package '{requestedPackage}' with WithCargoPackage, but \" +","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Rust/RustCargoTargetResolver.cs#L132-L168","documentation":"ResolveBinaryName maps a cargo package to the executable it produces, and throws this DistributedApplicationException when the resolved package declares zero binary targets (empty BinTargetNames). Without a bin target there is no executable path for run/debug, and suggesting WithCargoBinTarget would point at a target that cannot exist, so the message instead directs the user to a package that actually produces a binary. It is thrown up front so the failure happens before any build attempt.","triggerScenarios":"Adding a RustAppResource whose app directory resolves (via 'cargo metadata') to a library-only crate, with no WithCargoPackage or WithCargoBinTarget specified and zero packages with binary targets in the default workspace members.","commonSituations":"Pointing the Rust integration at a src/ directory containing only library crates (e.g. a shared lib crate); a Cargo.toml with no [[bin]] section and no src/main.rs; workspace layouts where the default member picked is lib-only.","solutions":["Point the resource at a directory whose package contains a binary target (src/main.rs or a [[bin]] section)","Call .WithCargoPackage(\"<name>\") to select a workspace package that has a binary target","Add a [[bin]] target or src/main.rs to the crate if it is supposed to produce an executable"],"exampleFix":"// before\nbuilder.AddRustApp(\"app\", \"../rust-lib\"); // lib-only crate\n// after\nbuilder.AddRustApp(\"app\", \"../rust-workspace\")\n       .WithCargoPackage(\"my-server\"); // package with a binary target","handlingStrategy":"validation","validationCode":"var meta = RunCargoMetadata(appDir);\nif (meta.Packages.All(p => p.BinTargetNames.Count == 0)) throw new InvalidOperationException(\"No package in the workspace declares a binary target.\");","typeGuard":"bool HasRunnablePackage(CargoMetadata m) => m.Packages.Any(p => p.BinTargetNames.Count > 0);","tryCatchPattern":"try { builder.AddRustApp(\"app\", dir); } catch (DistributedApplicationException ex) when (ex.Message.Contains(\"declares no\")) { log.LogError(ex, \"Rust package has no bin target\"); }","preventionTips":["Ensure the target crate has src/main.rs or a [[bin]] section before wiring it up","Run 'cargo metadata --no-deps' and check for bins before configuring the resource","Use WithCargoPackage to point at a known runnable crate in multi-crate workspaces"],"tags":["rust","cargo","binary-target","configuration"],"backgroundTag":"resource-not-found","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"}