{"record":{"id":"1b57d595da03c745","repo":"RicoSuter/NSwag","slug":"project-outputs-could-not-be-located-in-projectmetadata","errorCode":null,"errorMessage":"Project outputs could not be located in '{projectMetadata.OutputPath}'. Ensure that the project has been built.","messagePattern":"Project outputs could not be located in '(.+?)'\\. Ensure that the project has been built\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiCommand.cs","lineNumber":79,"sourceCode":"\n        public override async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host)\n        {\n            var verboseHost = Verbose ? host : null;\n\n            var projectFile = ProjectMetadata.FindProject(Project);\n            var projectMetadata = await ProjectMetadata.GetProjectMetadata(\n                projectFile,\n                MSBuildProjectExtensionsPath,\n                TargetFramework,\n                Configuration,\n                Runtime,\n                NoBuild,\n                MSBuildOutputPath,\n                verboseHost).ConfigureAwait(false);\n\n            if (!File.Exists(Path.Combine(projectMetadata.OutputPath, projectMetadata.TargetFileName)))\n            {\n                throw new InvalidOperationException($\"Project outputs could not be located in \" +\n                                                    $\"'{projectMetadata.OutputPath}'. Ensure that the project has been built.\");\n            }\n\n            var cleanupFiles = new List<string>();\n\n            var args = new List<string>();\n            string executable;\n\n#if NET462\n            var toolDirectory = AppDomain.CurrentDomain.BaseDirectory;\n            if (!Directory.Exists(toolDirectory))\n            {\n                toolDirectory = Path.GetDirectoryName(typeof(AspNetCoreToOpenApiCommand).GetTypeInfo().Assembly.Location);\n            }\n\n            if (projectMetadata.TargetFrameworkIdentifier == \".NETFramework\")\n            {\n                string binaryName;","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiCommand.cs#L61-L97","documentation":"NSwag's aspnetcore2openapi command runs MSBuild to resolve the project's OutputPath and TargetFileName, then checks that the built assembly actually exists there before launching the generation process. If the output assembly is missing it throws this InvalidOperationException, because the launcher binary and the target app must live side-by-side in the output directory. It usually means the project was not built (or was built to a different output path/framework/configuration than NSwag evaluated).","triggerScenarios":"Running `nswag aspnetcore2openapi` (AspNetCoreToOpenApiCommand.RunAsync) where File.Exists(Path.Combine(projectMetadata.OutputPath, projectMetadata.TargetFileName)) is false. Typically triggered with --nobuild on a never-built or stale project, a mismatched --configuration (Release vs Debug), a custom --outputpath, or a wrong --targetframework/--runtime that resolves to an empty bin subfolder.","commonSituations":"Fresh clone where CI calls nswag with --nobuild before `dotnet build`; multi-targeted project where NSwag evaluates a framework that was never restored; passing an OutputPath that differs from the build's actual output; deleting bin/obj then regenerating the spec without rebuilding.","solutions":["Remove the --nobuild flag (or run `dotnet build` on the project first) so NSwag builds before locating outputs.","Verify the target framework, configuration, and runtime flags match an actual built configuration (check bin/<Configuration>/<TFM>).","If you use a custom output path, pass the same value via --outputpath / MSBuildOutputPath so NSwag resolves the same directory.","Clear stale bin/obj and rebuild to fix corrupted incremental build state."],"exampleFix":"// before\nnswag aspnetcore2openapi /project:MyApi.csproj /nobuild:true\n// after\ndotnet build MyApi.csproj -c Release\nnswag aspnetcore2openapi /project:MyApi.csproj /configuration:Release /nobuild:true","handlingStrategy":"validation","validationCode":"var outDir = Path.Combine(projectDir, \"bin\", configuration ?? \"Debug\");\nif (!Directory.EnumerateFiles(outDir, \"*.dll\").Any())\n    throw new InvalidOperationException(\"Build the project before running nswag aspnetcore2openapi (avoid --nobuild on a clean checkout).\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run `dotnet build` before `nswag aspnetcore2openapi` when using --nobuild.","Keep --configuration/--targetframework/--runtime flags identical between build and spec generation steps.","Avoid custom OutputPath unless you pass it to NSwag too."],"tags":["dotnet","msbuild","build-output","cli"],"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"}