{"record":{"id":"890ba88b97108b9d","repo":"RicoSuter/NSwag","slug":"no-project-csproj-file-could-be-found-under-directory-path","errorCode":null,"errorMessage":"No project (.csproj) file could be found under directory {path}.","messagePattern":"No project \\(\\.csproj\\) file could be found under directory (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Commands/Commands/Generation/AspNetCore/ProjectMetadata.cs","lineNumber":62,"sourceCode":"        public string TargetFileName { get; set; }\n        public string TargetFrameworkIdentifier { get; set; }\n\n        public static string FindProject(string path)\n        {\n            if (path == null)\n            {\n                path = Directory.GetCurrentDirectory();\n            }\n            else if (!Directory.Exists(path))\n            {\n                // It's not a directory. Treat the input path as the project file.\n                return path;\n            }\n\n            var projectFiles = Directory.GetFiles(path, \"*.csproj\");\n            if (projectFiles.Length == 0)\n            {\n                throw new InvalidOperationException($\"No project (.csproj) file could be found under directory {path}.\");\n            }\n            else if (projectFiles.Length > 1)\n            {\n                throw new InvalidOperationException($\"More than one project was found in directory '{path}'. Specify one using its file name.\");\n            }\n\n            return projectFiles[0];\n        }\n\n        public static async Task<ProjectMetadata> GetProjectMetadata(\n            string file,\n            string buildExtensionsDir,\n            string framework,\n            string configuration,\n            string runtime,\n            bool noBuild,\n            string outputPath,\n            IConsoleHost console = null)","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Commands/Commands/Generation/AspNetCore/ProjectMetadata.cs#L44-L80","documentation":"ProjectMetadata.FindProject resolves the Project argument: a null path falls back to the current working directory, and a non-directory path is treated as the project file itself. If the given (or current) directory contains no *.csproj files, FindProject throws this error because NSwag cannot determine which project to build and inspect.","triggerScenarios":"Running `nswag aspnetcore2openapi` from a directory containing no .csproj (with no /project argument), or passing a directory path that has no .csproj directly inside it (the search is not recursive).","commonSituations":"Running nswag from a solution root or src/ folder one level above the project; project file uses a different extension (.vbproj, .fsproj) which the *.csproj glob misses; passing the solution file (.sln) instead of a project; typo'd project directory path.","solutions":["Pass the project file explicitly: `/project:path/to/MyApi.csproj`.","Run nswag from the directory that directly contains the .csproj.","For non-C# projects use the appropriate project file path — note FindProject only globs *.csproj, so pass the file path directly.","Ensure you pass a project file, not a .sln, since solutions are not supported here."],"exampleFix":"// before\nnswag aspnetcore2openapi   (run from repo root, no csproj here)\n// after\nnswag aspnetcore2openapi /project:src/MyApi/MyApi.csproj","handlingStrategy":"validation","validationCode":"var dir = projectArg ?? Directory.GetCurrentDirectory();\nif (Directory.Exists(dir) && !Directory.EnumerateFiles(dir, \"*.csproj\").Any())\n    throw new InvalidOperationException($\"No .csproj directly under {dir}; pass /project: explicitly.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await command.RunAsync(processor, host);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No project (.csproj) file could be found\"))\n{\n    // retry with an explicit /project path\n}","preventionTips":["Always pass an explicit /project:path/to.csproj in scripts and CI.","Run nswag from the project directory, not the repo or solution root.","Remember the glob is non-recursive and only matches *.csproj."],"tags":["cli","project-file","path"],"backgroundTag":"file-not-found","analyzedSha":"63daf8fcc3a25151b62eb4b326a1e8ea048a0d41","analyzedAt":"2026-09-14T11:38:15.205Z","contentChangedAt":"2026-09-14T11:38:15.205Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}