dotnet/reactive · error · InvalidOperationException
Multiple .nupkg files found after packing the project
Error message
Multiple .nupkg files found after packing the project
What it means
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.
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
Example fix
// before: leftover packages accumulate in a shared folder dotnet pack -o ./artifacts // after: clean first so exactly one nupkg is produced rm -rf ./artifacts && dotnet pack -o ./artifacts
Defensive patterns
Strategy: validation
Validate before calling
var stale = Directory.GetFiles(outDir, "*.nupkg", SearchOption.AllDirectories); if (stale.Length > 0) Directory.Delete(outDir, recursive: true); // clean before pack
Try / catch
try
{
var results = await builder.BuildLocalNuGetPackageAsync(...);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Multiple .nupkg files"))
{
// clean output folder and re-pack
} Prevention
- 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
When it happens
Trigger: Directory.GetFiles(..., '*.nupkg', AllDirectories) returns 2+ files — usually leftover .nupkg from a previous pack with a different version, or symbols/config variants in subfolders.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Unexpected failure when building NuGet package to be…
- No .nupkg file found after packing the project
- PlugIn host executable not found at
- Template csproj path should be absolute
- Template csproj path should refer to a file, not a directory
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/8d8f8cd757a9ae6f.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Test/Gauntlet/RxGauntlet.Common/Build/ComponentBuilder.cs:34
{
(string projectTemplateFileName, ModifiedProjectClone projectClone) = CreateModifiedProjectClone(
PackageTempFolderName, templateCsProj, modifyProjectFile, additionalPackageSources);
BuildOutput packResults = await projectClone.RunDotnetPack(projectTemplateFileName);
if (!Directory.Exists(LocalNuGetPackageFolderPath))
{
Directory.CreateDirectory(LocalNuGetPackageFolderPath);
}
string nupkgPath = Directory.GetFiles(
packResults.OutputFolder,
"*.nupkg",
SearchOption.AllDirectories) switch
{
[] => throw new InvalidOperationException("No .nupkg file found after packing the project"),
[string nupkgFile] => nupkgFile,
_ => throw new InvalidOperationException("Multiple .nupkg files found after packing the project")
};
string destinationNupkgPath = Path.Combine(LocalNuGetPackageFolderPath, Path.GetFileName(nupkgPath));
File.Copy(nupkgPath, destinationNupkgPath);
return packResults;
}
/// <summary>
///
/// </summary>
/// <param name="templateCsProj"></param>
/// <param name="modifyProjectFile"></param>
/// <param name="additionalPackageSources"></param>
/// <returns>
/// A task that produces the path to the <c>bin\Release</c> folder of the built application.
/// </returns>
public async Task<BuildOutput> BuildAppAsync(View on GitHub (pinned to 94b5d5ab91)