microsoft/aspire · error · ProjectLocatorException

No project file found.

Error message

No project file found.

What it means

This error is ProjectLocatorException with ErrorStrings.NoProjectFileFound and reason UnsupportedProjects. It fires when no AppHost project was found in the directory, but the file search did encounter project files the CLI does not support (UnsupportedProjects under the searched directory). The CLI deliberately distinguishes 'nothing here at all' from 'unsupported project types present' so the user learns why their .csproj wasn't picked.

Solutions

  1. Run the command from the directory containing the AppHost project (or pass --project pointing at the AppHost csproj).
  2. Ensure the AppHost project references Aspire.Hosting.AppHost and the Aspire.AppHost.Sdk so it's recognized as an AppHost.
  3. Move or rename unsupported project files out of the search directory if they shadow discovery.
  4. Handle ProjectLocatorException with FailureReason UnsupportedProjects in scripts to print a targeted message.

Example fix

// before
aspire run   # from solution root, no AppHost here
// after
aspire run --project ./MyApp.AppHost/MyApp.AppHost.csproj
Defensive patterns

Strategy: validation

Validate before calling

var csprojs = Directory.EnumerateFiles(dir, "*.csproj", SearchOption.AllDirectories);
Console.WriteLine($"Found {(csprojs.Any() ? "project files (possibly unsupported types)" : "no project files")} under {dir}");

Type guard

static bool LooksLikeAppHost(string csprojPath) =>
    File.ReadAllText(csprojPath).Contains("Aspire.AppHost.Sdk") || File.ReadAllText(csprojPath).Contains("Aspire.Hosting.AppHost");

Try / catch

try { var appHost = await locator.UseAppHostAsync(ct); }
catch (ProjectLocatorException ex) when (ex.FailureReason == ProjectLocatorFailureReason.UnsupportedProjects)
{ Console.WriteLine("Only unsupported project types found — run from the AppHost directory or pass --project."); }

Prevention

When it happens

Trigger: Running an AppHost-requiring CLI command in a directory with no AppHost csproj, while unsupported project files (e.g. non-AppHost project types or unsupported SDK styles) exist under that directory.

Common situations: Running aspire run in a solution root or library folder instead of the AppHost folder; project uses a legacy/unsupported project format; the AppHost csproj is present but lacks the Aspire AppHost project-capability so it lands in UnsupportedProjects.

Related errors


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

Appendix: source

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

                            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)
                    {
                        logger.LogDebug("Multiple AppHost project files found in directory {Directory}, prompting user to select", directory.FullName);
                        explicitSelectionWasPrompted = true;
                        projectFile = await interactionService.PromptForSelectionAsync(
                            InteractionServiceStrings.SelectAppHostToUse,

View on GitHub (pinned to 25830f84bd)