microsoft/aspire · error · ProjectLocatorException

No buildable AppHosts were found, but there may have been…

Error message

No buildable AppHosts were found, but there may have been unbuildable AppHosts.

What it means

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.

Solutions

  1. Fix the underlying build failure: run dotnet build on the candidate AppHost(s) and address the SDK/restore error reported.
  2. Install or switch to the .NET SDK version the AppHost projects target (global.json / TargetFramework).
  3. Repair or remove the broken AppHost project files so at least one is buildable in the scanned directory.
  4. Catch ProjectLocatorException and inspect the FailureReason (AppHostsMayNotBeBuildable) to branch automation accordingly.

Example fix

// before: AppHost targets net10.0 but only net8 SDK installed
<TargetFramework>net10.0</TargetFramework>
// after: install .NET 10 SDK, or retarget if intended
<TargetFramework>net8.0</TargetFramework>
Defensive patterns

Strategy: try-catch

Validate before calling

var search = appHostSearcher.Search(directory);
if (search.Unbuildable.Count > 0)
    Console.WriteLine($"Unbuildable AppHosts present: {string.Join(", ", search.Unbuildable.Select(f => f.FullName))} — fix or remove them.");

Type guard

static bool HasBuildableAppHost(AppHostProjectSearchResult r) => r.ProjectFile is not null && r.Unbuildable.Count == 0;

Try / catch

try { var appHost = await locator.UseAppHostAsync(ct); }
catch (ProjectLocatorException ex) when (ex.FailureReason == ProjectLocatorFailureReason.AppHostsMayNotBeBuildable)
{ Console.WriteLine("AppHost projects exist but are not buildable — check SDK version and dotnet build output."); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/e02848507328cd70. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Cli/Projects/ProjectLocator.cs:945

                    if (unbuildableInDirectory.Count == 1)
                    {
                        var unbuildableAppHost = unbuildableInDirectory[0].AppHostFile;
                        logger.LogDebug(
                            "Selecting AppHost project file {ProjectFile} in directory {Directory} even though MSBuild could not evaluate it.",
                            unbuildableAppHost.FullName,
                            directory.FullName);

                        // Deliberately skip CreateSettingsFileAsync: this candidate was never confirmed to
                        // be an AppHost, so persisting it would make later ambient invocations silently
                        // reuse an unverified guess.
                        return new AppHostProjectSearchResult(unbuildableAppHost, [unbuildableAppHost]);
                    }

                    if (unbuildableInDirectory.Count > 1)
                    {
                        // Several broken candidates under one directory is a genuine ambiguity rather than
                        // a user selection, so this stays a project-resolution failure.
                        throw new ProjectLocatorException(ErrorStrings.AppHostsMayNotBeBuildable, ProjectLocatorFailureReason.AppHostsMayNotBeBuildable);
                    }

                    if (searchResults.UnsupportedProjects.Any(file => IsUnderDirectory(file, directory)))
                    {
                        throw new ProjectLocatorException(ErrorStrings.NoProjectFileFound, ProjectLocatorFailureReason.UnsupportedProjects);
                    }

                    logger.LogError("No AppHost project files found in directory {Directory}", directory.FullName);
                    throw new ProjectLocatorException(ErrorStrings.ProjectFileDoesntExist, ProjectLocatorFailureReason.ProjectFileDoesntExist);
                }
                else if (appHostProjects.Count == 1)
                {
                    logger.LogDebug("Found single AppHost project file {ProjectFile} in directory {Directory}", appHostProjects[0].FullName, directory.FullName);
                    projectFile = appHostProjects[0];
                }
                else
                {
                    if (multipleAppHostProjectsFoundBehavior is MultipleAppHostProjectsFoundBehavior.Prompt)

View on GitHub (pinned to 25830f84bd)