{"record":{"id":"2bd3af3a13a59790","repo":"microsoft/aspire","slug":"build-failed-for-resource-resource-name-with-exit-code","errorCode":null,"errorMessage":"Build failed for resource '{resource.Name}' with exit code {process.ExitCode}.","messagePattern":"Build failed for resource '(.+?)' with exit code (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Maui/Lifecycle/MauiBuildQueueEventSubscriber.cs","lineNumber":252,"sourceCode":"            TryKillProcess(process, logger);\n            throw new TimeoutException(\n                $\"Build for resource '{resource.Name}' timed out after {BuildTimeout:c}.\");\n        }\n        catch (OperationCanceledException)\n        {\n            TryKillProcess(process, logger);\n            throw;\n        }\n        finally\n        {\n            // Always drain remaining output — even on cancellation the process was killed\n            // and the streams will reach EOF, so the tasks will complete promptly.\n            await Task.WhenAll(stdoutTask, stderrTask).ConfigureAwait(false);\n        }\n\n        if (process.ExitCode != 0)\n        {\n            throw new InvalidOperationException(\n                $\"Build failed for resource '{resource.Name}' with exit code {process.ExitCode}.\");\n        }\n\n        logger.LogInformation(\"Build succeeded for resource '{ResourceName}'.\", resource.Name);\n    }\n\n    private static async Task PipeOutputAsync(System.IO.StreamReader reader, ILogger logger, LogLevel level, CancellationToken cancellationToken)\n    {\n        try\n        {\n            while (!cancellationToken.IsCancellationRequested)\n            {\n                var line = await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false);\n                if (line is null)\n                {\n                    break;\n                }\n","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Maui/Lifecycle/MauiBuildQueueEventSubscriber.cs#L234-L270","documentation":"After the MAUI build process exits, RunBuildAsync checks its exit code. A non-zero exit code means compilation/build failed; the subscriber throws InvalidOperationException with the exit code so the resource fails to start. Stdout/stderr are already drained and logged to help diagnose.","triggerScenarios":"The dotnet build invoked for the MAUI resource exits non-zero — compile errors, missing workloads (e.g. ios/android), missing TargetFrameworks, invalid signing/bundle settings — surfacing at src/Aspire.Hosting.Maui/Lifecycle/MauiBuildQueueEventSubscriber.cs:252.","commonSituations":"Missing MAUI workloads or SDKs on the machine; Xcode/Android SDK version mismatches; code compile errors after edits; NuGet restore failures; unsupported target framework for the selected platform.","solutions":["Read the captured build stdout/stderr logs near this error to find the actual MSBuild error, then fix that error.","Install/repair required workloads: dotnet workload install maui (plus maui-ios/maui-android/maui-maccatalyst as needed).","Verify the target platform SDKs (Xcode for MacCatalyst/iOS, Android SDK/SDK manager) are installed and version-compatible.","Build the MAUI project directly with dotnet build to reproduce and fix outside Aspire, then restart the AppHost."],"exampleFix":"// before\n// missing workload causes exit code 1\ndotnet run --project AppHost;\n// after\ndotnet workload install maui-ios maui-maccatalyst && dotnet run --project AppHost;","handlingStrategy":"try-catch","validationCode":"// pre-flight outside Aspire\nvar psi = new ProcessStartInfo(\"dotnet\", $\"build {mauiProject} -f {targetFramework}\"); // non-zero exit here predicts the Aspire error","typeGuard":null,"tryCatchPattern":"try { await startMauiResourceAsync(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Build failed\")) { // inspect captured build stdout/stderr logs for the MSBuild error }","preventionTips":["Install/repair MAUI workloads (dotnet workload install maui*) before starting","Verify Xcode/Android SDK versions match your MAUI version","Fix compile errors by building the MAUI project directly first","Ensure NuGet restore succeeds in the target environment"],"tags":["maui","build","process-exit-code","lifecycle"],"backgroundTag":"command-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}