{"record":{"id":"e02848507328cd70","repo":"microsoft/aspire","slug":"no-buildable-apphosts-were-found-but-there-may-have-been","errorCode":null,"errorMessage":"No buildable AppHosts were found, but there may have been unbuildable AppHosts.","messagePattern":"No buildable AppHosts were found, but there may have been unbuildable AppHosts\\.","errorType":"exception","errorClass":"ProjectLocatorException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Projects/ProjectLocator.cs","lineNumber":945,"sourceCode":"                    if (unbuildableInDirectory.Count == 1)\n                    {\n                        var unbuildableAppHost = unbuildableInDirectory[0].AppHostFile;\n                        logger.LogDebug(\n                            \"Selecting AppHost project file {ProjectFile} in directory {Directory} even though MSBuild could not evaluate it.\",\n                            unbuildableAppHost.FullName,\n                            directory.FullName);\n\n                        // Deliberately skip CreateSettingsFileAsync: this candidate was never confirmed to\n                        // be an AppHost, so persisting it would make later ambient invocations silently\n                        // reuse an unverified guess.\n                        return new AppHostProjectSearchResult(unbuildableAppHost, [unbuildableAppHost]);\n                    }\n\n                    if (unbuildableInDirectory.Count > 1)\n                    {\n                        // Several broken candidates under one directory is a genuine ambiguity rather than\n                        // a user selection, so this stays a project-resolution failure.\n                        throw new ProjectLocatorException(ErrorStrings.AppHostsMayNotBeBuildable, ProjectLocatorFailureReason.AppHostsMayNotBeBuildable);\n                    }\n\n                    if (searchResults.UnsupportedProjects.Any(file => IsUnderDirectory(file, directory)))\n                    {\n                        throw new ProjectLocatorException(ErrorStrings.NoProjectFileFound, ProjectLocatorFailureReason.UnsupportedProjects);\n                    }\n\n                    logger.LogError(\"No AppHost project files found in directory {Directory}\", directory.FullName);\n                    throw new ProjectLocatorException(ErrorStrings.ProjectFileDoesntExist, ProjectLocatorFailureReason.ProjectFileDoesntExist);\n                }\n                else if (appHostProjects.Count == 1)\n                {\n                    logger.LogDebug(\"Found single AppHost project file {ProjectFile} in directory {Directory}\", appHostProjects[0].FullName, directory.FullName);\n                    projectFile = appHostProjects[0];\n                }\n                else\n                {\n                    if (multipleAppHostProjectsFoundBehavior is MultipleAppHostProjectsFoundBehavior.Prompt)","sourceCodeStart":927,"sourceCodeEnd":963,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Projects/ProjectLocator.cs#L927-L963","documentation":"During AppHost discovery, ProjectLocator distinguishes buildable AppHosts from 'unbuildable' candidates (csproj files that failed eligibility checks). If nothing buildable was found but unbuildable candidates existed, throwing a generic 'no project found' would mislead, so the CLI throws ProjectLocatorException with ErrorStrings.AppHostsMayNotBeBuildable and reason AppHostsMayNotBeBuildable. The message text shown is this shared ErrorStrings resource; note that per the source, this specific throw fires when several broken candidates share one directory (genuine ambiguity), while fewer broken candidates fall through to interactive selection.","triggerScenarios":"Running any command that needs an AppHost (aspire run/publish/etc.) in a directory where AppHost project files exist but none are buildable, and specifically where multiple unbuildable AppHosts sit in the same directory — often because the projects target an unsupported or missing SDK/framework or have invalid project files.","commonSituations":"Cloned solution with AppHosts that require a newer .NET SDK than installed; corrupted csproj files; projects failing restore so they can't be evaluated as buildable; working from the wrong directory where several stale/broken AppHost projects live.","solutions":["Fix the underlying build failure: run dotnet build on the candidate AppHost(s) and address the SDK/restore error reported.","Install or switch to the .NET SDK version the AppHost projects target (global.json / TargetFramework).","Repair or remove the broken AppHost project files so at least one is buildable in the scanned directory.","Catch ProjectLocatorException and inspect the FailureReason (AppHostsMayNotBeBuildable) to branch automation accordingly."],"exampleFix":"// before: AppHost targets net10.0 but only net8 SDK installed\n<TargetFramework>net10.0</TargetFramework>\n// after: install .NET 10 SDK, or retarget if intended\n<TargetFramework>net8.0</TargetFramework>","handlingStrategy":"try-catch","validationCode":"var search = appHostSearcher.Search(directory);\nif (search.Unbuildable.Count > 0)\n    Console.WriteLine($\"Unbuildable AppHosts present: {string.Join(\", \", search.Unbuildable.Select(f => f.FullName))} — fix or remove them.\");","typeGuard":"static bool HasBuildableAppHost(AppHostProjectSearchResult r) => r.ProjectFile is not null && r.Unbuildable.Count == 0;","tryCatchPattern":"try { var appHost = await locator.UseAppHostAsync(ct); }\ncatch (ProjectLocatorException ex) when (ex.FailureReason == ProjectLocatorFailureReason.AppHostsMayNotBeBuildable)\n{ Console.WriteLine(\"AppHost projects exist but are not buildable — check SDK version and dotnet build output.\"); }","preventionTips":["Run dotnet build on AppHost projects after cloning to surface SDK/framework gaps early.","Install the SDK version pinned in global.json.","Keep only working AppHost projects in directories the CLI scans.","Fix or remove broken csproj files rather than leaving them in place."],"tags":["cli","project-resolution","apphost","build"],"backgroundTag":"project-not-buildable","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"}