{"record":{"id":"8d8f8cd757a9ae6f","repo":"dotnet/reactive","slug":"multiple-nupkg-files-found-after-packing-the-project","errorCode":null,"errorMessage":"Multiple .nupkg files found after packing the project","messagePattern":"Multiple \\.nupkg files found after packing the project","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Test/Gauntlet/RxGauntlet.Common/Build/ComponentBuilder.cs","lineNumber":34,"sourceCode":"    {\n        (string projectTemplateFileName, ModifiedProjectClone projectClone) = CreateModifiedProjectClone(\n            PackageTempFolderName, templateCsProj, modifyProjectFile, additionalPackageSources);\n\n        BuildOutput packResults = await projectClone.RunDotnetPack(projectTemplateFileName);\n\n        if (!Directory.Exists(LocalNuGetPackageFolderPath))\n        {\n            Directory.CreateDirectory(LocalNuGetPackageFolderPath);\n        }\n\n        string nupkgPath = Directory.GetFiles(\n            packResults.OutputFolder,\n            \"*.nupkg\",\n            SearchOption.AllDirectories) switch\n        {\n            [] => throw new InvalidOperationException(\"No .nupkg file found after packing the project\"),\n            [string nupkgFile] => nupkgFile,\n            _ => throw new InvalidOperationException(\"Multiple .nupkg files found after packing the project\")\n        };\n\n        string destinationNupkgPath = Path.Combine(LocalNuGetPackageFolderPath, Path.GetFileName(nupkgPath));\n        File.Copy(nupkgPath, destinationNupkgPath);\n\n        return packResults;\n    }\n\n    /// <summary>\n    /// \n    /// </summary>\n    /// <param name=\"templateCsProj\"></param>\n    /// <param name=\"modifyProjectFile\"></param>\n    /// <param name=\"additionalPackageSources\"></param>\n    /// <returns>\n    /// A task that produces the path to the <c>bin\\Release</c> folder of the built application.\n    /// </returns>\n    public async Task<BuildOutput> BuildAppAsync(","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Test/Gauntlet/RxGauntlet.Common/Build/ComponentBuilder.cs#L16-L52","documentation":"In the same pattern match in BuildLocalNuGetPackageAsync, if more than one *.nupkg is found in the output folder the builder throws InvalidOperationException('Multiple .nupkg files found after packing the project'). The builder needs exactly one package to copy into the local feed, so ambiguity is treated as a hard failure.","triggerScenarios":"Directory.GetFiles(..., '*.nupkg', AllDirectories) returns 2+ files — usually leftover .nupkg from a previous pack with a different version, or symbols/config variants in subfolders.","commonSituations":"Re-packing after a version bump leaves the old versioned nupkg in bin; SymbolPackage or per-TFM duplicates under the output tree; stale artifacts from prior builds never cleaned.","solutions":["Clean the output folder (bin/obj and pack output) before packing so only one nupkg exists","Delete stale .nupkg files with older versions from the output tree","Make the pack output go to a fresh per-build folder instead of a shared one","If multiple packages are intentional, change the builder to select by exact PackageId"],"exampleFix":"// before: leftover packages accumulate in a shared folder\ndotnet pack -o ./artifacts\n// after: clean first so exactly one nupkg is produced\nrm -rf ./artifacts && dotnet pack -o ./artifacts","handlingStrategy":"validation","validationCode":"var stale = Directory.GetFiles(outDir, \"*.nupkg\", SearchOption.AllDirectories);\nif (stale.Length > 0) Directory.Delete(outDir, recursive: true); // clean before pack","typeGuard":null,"tryCatchPattern":"try\n{\n    var results = await builder.BuildLocalNuGetPackageAsync(...);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Multiple .nupkg files\"))\n{\n    // clean output folder and re-pack\n}","preventionTips":["Pack into a fresh, uniquely named output folder per build","Delete old versioned nupkg files after version bumps","Do not mix symbols/regular packages in the searched tree","Keep one package per project; select by exact PackageId if multiple are unavoidable"],"tags":["nuget","pack","ambiguous-output","build"],"backgroundTag":"internal-invariant-violation","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}