{"record":{"id":"d5b3331a06d5cf4c","repo":"microsoft/aspire","slug":"failed-to-discover-the-blazor-webassembly-client-project-for","errorCode":null,"errorMessage":"Failed to discover the Blazor WebAssembly client project for '{serverProjectPath}'. The ResolveWebAssemblyProjectReferences MSBuild target exited with code {result.ExitCode}.","messagePattern":"Failed to discover the Blazor WebAssembly client project for '(.+?)'\\. The ResolveWebAssemblyProjectReferences MSBuild target exited with code (.+?)\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"critical","filePath":"src/Aspire.Hosting.Blazor/BlazorHostedExtensions.cs","lineNumber":238,"sourceCode":"            cancellationToken).ConfigureAwait(false);\n\n        if (!result.Started)\n        {\n            var message =\n                $\"Failed to start '{result.Command}' while discovering the Blazor WebAssembly client project for '{serverProjectPath}'.\";\n            throw result.StartException is not null\n                ? new DistributedApplicationException(message, result.StartException)\n                : new DistributedApplicationException(message);\n        }\n\n        if (result.ExitCode != 0)\n        {\n            BlazorGatewayLog.WasmClientDiscoveryFailed(\n                logger,\n                serverProjectPath,\n                result.StandardOutput,\n                result.StandardError);\n            throw new DistributedApplicationException(\n                $\"Failed to discover the Blazor WebAssembly client project for '{serverProjectPath}'. \" +\n                $\"The ResolveWebAssemblyProjectReferences MSBuild target exited with code {result.ExitCode}.\");\n        }\n\n        if (string.IsNullOrWhiteSpace(result.StandardOutput))\n        {\n            throw new DistributedApplicationException(\n                $\"The ResolveWebAssemblyProjectReferences MSBuild target returned no output for '{serverProjectPath}'.\");\n        }\n\n        try\n        {\n            using var output = JsonDocument.Parse(result.StandardOutput);\n\n            // MSBuild emits:\n            // { \"Items\": { \"WebAssemblyProjectReference\": [{ \"Identity\": \"/path/Client.csproj\" }] } }\n            if (output.RootElement.TryGetProperty(\"Items\", out var items)\n                && items.TryGetProperty(\"WebAssemblyProjectReference\", out var projectReferences))","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Blazor/BlazorHostedExtensions.cs#L220-L256","documentation":"ResolveBlazorWasmClientProjectPathAsync runs an MSBuild process targeting ResolveWebAssemblyProjectReferences on the Blazor server project to find its WASM client project. When that process exits with a non-zero code, the library logs stdout/stderr and throws a DistributedApplicationException — the client project cannot be discovered.","triggerScenarios":"Calling the hosted-Blazor/gateway setup that must auto-discover the WASM client, while the MSBuild invocation on serverProjectPath fails (bad project path, invalid csproj, missing SDK, restore errors).","commonSituations":"Server project path wrong or moved; project file doesn't reference a WASM client; MSBuild/dotnet not on PATH or wrong SDK; solution restore out of date; custom build props breaking the target.","solutions":["Build/restore the server project manually (dotnet build/restore) to surface the underlying MSBuild error from result.StandardError in the logs.","Verify serverProjectPath points to the correct .csproj of a hosted Blazor server that references a WASM client.","Ensure the .NET SDK matching the project is installed and `dotnet msbuild` works in that directory.","Explicitly declare the WASM client relationship instead of relying on auto-discovery if your project layout is unusual."],"exampleFix":"// before\nvar host = builder.AddProject<Projects.Server>(\"server\"); // server moved/renamed\n// after\nvar host = builder.AddProject<Projects.ServerFixed>(\"server\"); // correct, buildable server project","handlingStrategy":"retry","validationCode":"var exit = Process.Run(\"dotnet\", $\"msbuild {serverProjectPath} -t:ResolveWebAssemblyProjectReferences\");\nif (exit.ExitCode != 0) throw new InvalidOperationException($\"Server project MSBuild discovery failed: {exit.StandardError}\");","typeGuard":null,"tryCatchPattern":"try { await ResolveBlazorWasmClientProjectPathAsync(...); } catch (DistributedApplicationException ex) when (ex.Message.Contains(\"exited with code\")) { logger.LogError(ex, \"Check logged stdout/stderr for the MSBuild failure\"); throw; }","preventionTips":["Restore and build the server project before running the AppHost.","Keep dotnet SDK on PATH and version-compatible with the project.","Ensure the server references a WASM client project.","Validate server project paths after renames/moves."],"tags":["blazor","msbuild","wasm","discovery","process-exit-code"],"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-21T04:17:39.646Z"}