microsoft/aspire · error · ProjectLocatorException

Project file does not exist.

Error message

Project file does not exist.

What it means

This is ProjectLocatorException with ErrorStrings.ProjectFileDoesntExist and reason ProjectFileDoesntExist, thrown when the directory contains no AppHost project files at all (and no unsupported projects explaining it). Before throwing, the CLI logs 'No AppHost project files found in directory {Directory}'. It is the plain 'you are in the wrong place / no AppHost here' resolution failure.

Solutions

  1. Create an AppHost with aspire init (or dotnet new aspire-apphost) in the directory.
  2. cd into the directory containing the AppHost project or pass --project <path-to-csproj>.
  3. Verify the AppHost csproj exists and wasn't renamed/excluded (git status, ls).
  4. Catch ProjectLocatorException and check FailureReason == ProjectLocatorFailureReason.ProjectFileDoesntExist in automation to report 'no AppHost here'.

Example fix

// before
aspire run        # empty directory
// after
aspire init && aspire run
Defensive patterns

Strategy: try-catch

Validate before calling

var appHosts = Directory.EnumerateFiles(dir, "*.csproj", SearchOption.AllDirectories)
    .Where(p => File.ReadAllText(p).Contains("Aspire.AppHost.Sdk"))
    .ToList();
if (appHosts.Count == 0) Console.WriteLine($"No AppHost project under {dir}; run 'aspire init' first.");

Type guard

static bool DirectoryHasAppHost(string dir) => Directory.EnumerateFiles(dir, "*.csproj", SearchOption.AllDirectories).Any(LooksLikeAppHost);

Try / catch

try { var appHost = await locator.UseAppHostAsync(ct); }
catch (ProjectLocatorException ex) when (ex.FailureReason == ProjectLocatorFailureReason.ProjectFileDoesntExist)
{ Console.WriteLine("No AppHost found in this directory — cd to the AppHost folder or run 'aspire init'."); }

Prevention

When it happens

Trigger: Running any command that requires an AppHost in an empty directory or one containing only non-AppHost files (web projects, class libraries) with no csproj matching the AppHost discovery criteria.

Common situations: Executing aspire run before creating a project (aspire init/new not run); wrong working directory; deleted or renamed AppHost project; CI checkout that only fetched part of the repo.

Related errors


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

Appendix: source

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

                        // 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,
                            appHostProjects,
                            file => $"{file.Name.EscapeMarkup()} ({Path.GetRelativePath(executionContext.WorkingDirectory.FullName, file.FullName).EscapeMarkup()})",
                            cancellationToken: cancellationToken
                        );

View on GitHub (pinned to 25830f84bd)