{"record":{"id":"b09111d9e6c86c29","repo":"microsoft/aspire","slug":"project-file-does-not-exist","errorCode":null,"errorMessage":"Project file does not exist.","messagePattern":"Project file does not exist\\.","errorType":"exception","errorClass":"ProjectLocatorException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Projects/ProjectLocator.cs","lineNumber":954,"sourceCode":"                        // 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)\n                    {\n                        logger.LogDebug(\"Multiple AppHost project files found in directory {Directory}, prompting user to select\", directory.FullName);\n                        explicitSelectionWasPrompted = true;\n                        projectFile = await interactionService.PromptForSelectionAsync(\n                            InteractionServiceStrings.SelectAppHostToUse,\n                            appHostProjects,\n                            file => $\"{file.Name.EscapeMarkup()} ({Path.GetRelativePath(executionContext.WorkingDirectory.FullName, file.FullName).EscapeMarkup()})\",\n                            cancellationToken: cancellationToken\n                        );","sourceCodeStart":936,"sourceCodeEnd":972,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Projects/ProjectLocator.cs#L936-L972","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Create an AppHost with aspire init (or dotnet new aspire-apphost) in the directory.","cd into the directory containing the AppHost project or pass --project <path-to-csproj>.","Verify the AppHost csproj exists and wasn't renamed/excluded (git status, ls).","Catch ProjectLocatorException and check FailureReason == ProjectLocatorFailureReason.ProjectFileDoesntExist in automation to report 'no AppHost here'."],"exampleFix":"// before\naspire run        # empty directory\n// after\naspire init && aspire run","handlingStrategy":"try-catch","validationCode":"var appHosts = Directory.EnumerateFiles(dir, \"*.csproj\", SearchOption.AllDirectories)\n    .Where(p => File.ReadAllText(p).Contains(\"Aspire.AppHost.Sdk\"))\n    .ToList();\nif (appHosts.Count == 0) Console.WriteLine($\"No AppHost project under {dir}; run 'aspire init' first.\");","typeGuard":"static bool DirectoryHasAppHost(string dir) => Directory.EnumerateFiles(dir, \"*.csproj\", SearchOption.AllDirectories).Any(LooksLikeAppHost);","tryCatchPattern":"try { var appHost = await locator.UseAppHostAsync(ct); }\ncatch (ProjectLocatorException ex) when (ex.FailureReason == ProjectLocatorFailureReason.ProjectFileDoesntExist)\n{ Console.WriteLine(\"No AppHost found in this directory — cd to the AppHost folder or run 'aspire init'.\"); }","preventionTips":["Create the AppHost (aspire init / dotnet new aspire-apphost) before running AppHost commands.","Confirm the working directory before invoking CLI commands in scripts.","Pass --project in CI so resolution never depends on cwd.","Verify repo checkout completeness before running the CLI."],"tags":["cli","project-resolution","apphost","discovery"],"backgroundTag":"project-file-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"}