{"record":{"id":"a6b9e82166b19ddf","repo":"RicoSuter/NSwag","slug":"more-than-one-project-was-found-in-directory-path-specify","errorCode":null,"errorMessage":"More than one project was found in directory '{path}'. Specify one using its file name.","messagePattern":"More than one project was found in directory '(.+?)'\\. Specify one using its file name\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Commands/Commands/Generation/AspNetCore/ProjectMetadata.cs","lineNumber":66,"sourceCode":"        {\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)\n        {\n            Debug.Assert(!string.IsNullOrEmpty(file), \"file is null or empty.\");\n\n            var args = CreateMsBuildArguments(file, framework, configuration, runtime, noBuild, outputPath);","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Commands/Commands/Generation/AspNetCore/ProjectMetadata.cs#L48-L84","documentation":"When the Project argument resolves to a directory containing more than one *.csproj file, FindProject refuses to guess and throws this error, asking the caller to name the exact project file. This ambiguity check exists because NSwag can only generate a spec from a single executable project.","triggerScenarios":"Calling `nswag aspnetcore2openapi /project:someDir` (or running in the current directory) where `Directory.GetFiles(path, \"*.csproj\")` returns 2+ files — e.g. a folder with both the API project and a test/helper csproj.","commonSituations":"Solution folders that keep main and test projects in the same directory; legacy non-SDK-style layouts with multiple csproj in one folder; monorepo checkouts where the working directory aggregates several projects.","solutions":["Specify the exact project file: `/project:src/MyApi/MyApi.csproj` instead of a directory.","Change the working directory to the folder containing only the desired project and run without /project.","Move helper/test csproj files into their own directories if you want directory-based resolution to work.","In an nswag.json config, set the `project` property to the full csproj path."],"exampleFix":"// before\nnswag aspnetcore2openapi /project:src\n// after\nnswag aspnetcore2openapi /project:src/MyApi/MyApi.csproj","handlingStrategy":"validation","validationCode":"var csprojs = Directory.GetFiles(dir, \"*.csproj\");\nif (csprojs.Length > 1)\n    Console.WriteLine($\"Ambiguous directory {dir}: pass one of {string.Join(\", \", csprojs)} explicitly.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await command.RunAsync(processor, host);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"More than one project was found\"))\n{\n    // retry with the exact csproj file path\n}","preventionTips":["Prefer explicit project file paths over directories in all automation.","Keep one csproj per directory so directory-based resolution stays unambiguous.","In nswag.json, always set the `project` property to a full csproj path."],"tags":["cli","ambiguous-path","project-file"],"backgroundTag":"ambiguous-target","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"}