{"record":{"id":"e6393f0b6728280d","repo":"microsoft/aspire","slug":"no-project-file-found","errorCode":null,"errorMessage":"No project file found.","messagePattern":"No project file found\\.","errorType":"exception","errorClass":"ProjectLocatorException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Projects/ProjectLocator.cs","lineNumber":950,"sourceCode":"                            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)\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,","sourceCodeStart":932,"sourceCodeEnd":968,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Projects/ProjectLocator.cs#L932-L968","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the command from the directory containing the AppHost project (or pass --project pointing at the AppHost csproj).","Ensure the AppHost project references Aspire.Hosting.AppHost and the Aspire.AppHost.Sdk so it's recognized as an AppHost.","Move or rename unsupported project files out of the search directory if they shadow discovery.","Handle ProjectLocatorException with FailureReason UnsupportedProjects in scripts to print a targeted message."],"exampleFix":"// before\naspire run   # from solution root, no AppHost here\n// after\naspire run --project ./MyApp.AppHost/MyApp.AppHost.csproj","handlingStrategy":"validation","validationCode":"var csprojs = Directory.EnumerateFiles(dir, \"*.csproj\", SearchOption.AllDirectories);\nConsole.WriteLine($\"Found {(csprojs.Any() ? \"project files (possibly unsupported types)\" : \"no project files\")} under {dir}\");","typeGuard":"static bool LooksLikeAppHost(string csprojPath) =>\n    File.ReadAllText(csprojPath).Contains(\"Aspire.AppHost.Sdk\") || File.ReadAllText(csprojPath).Contains(\"Aspire.Hosting.AppHost\");","tryCatchPattern":"try { var appHost = await locator.UseAppHostAsync(ct); }\ncatch (ProjectLocatorException ex) when (ex.FailureReason == ProjectLocatorFailureReason.UnsupportedProjects)\n{ Console.WriteLine(\"Only unsupported project types found — run from the AppHost directory or pass --project.\"); }","preventionTips":["Run AppHost commands from the AppHost project directory or pass --project explicitly.","Ensure the AppHost csproj uses the Aspire.AppHost.Sdk and references Aspire.Hosting.AppHost.","Avoid mixing legacy project formats into AppHost discovery directories.","Script against FailureReason values rather than message text."],"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"}