chocolatey/choco · error · ArgumentException
Package Path not a .nupkg or .nuspec
Error message
Package Path not a .nupkg or .nuspec
What it means
Thrown by the ChocolateyPackageMetadata constructor when the provided packagePath does not have a .nupkg extension (checked via NuGetConstants.PackageExtension) and does not have a .nuspec extension (NuGetConstants.ManifestExtension). The constructor only knows how to read metadata from these two file formats using NuGet's PackageArchiveReader and NuspecReader respectively. Any other file type or path is rejected before attempting to parse.
Source
Thrown at src/chocolatey/infrastructure.app/domain/ChocolateyPackageMetadata.cs:154
DevelopmentDependency = reader.GetDevelopmentDependency();
Description = reader.GetDescription();
Summary = reader.GetSummary();
ReleaseNotes = reader.GetReleaseNotes();
Language = reader.GetLanguage();
Tags = reader.GetTags();
Serviceable = reader.IsServiceable();
Copyright = reader.GetCopyright();
Icon = reader.GetIcon();
Readme = reader.GetReadme();
DependencyGroups = reader.GetDependencyGroups();
PackageTypes = reader.GetPackageTypes();
Repository = reader.GetRepositoryMetadata();
LicenseMetadata = reader.GetLicenseMetadata();
FrameworkReferenceGroups = reader.GetFrameworkRefGroups();
}
else
{
throw new ArgumentException("Package Path not a .nupkg or .nuspec");
}
}
public Uri ProjectSourceUrl { get; }
public Uri PackageSourceUrl { get; }
public Uri DocsUrl { get; }
public Uri WikiUrl { get; }
public Uri MailingListUrl { get; }
public Uri BugTrackerUrl { get; }
public IEnumerable<string> Replaces { get; }
public IEnumerable<string> Provides { get; }
public IEnumerable<string> Conflicts { get; }
public string SoftwareDisplayName { get; }
public string SoftwareDisplayVersion { get; }
public string Id { get; }
public NuGetVersion Version { get; private set; }
public string Title { get; }
public IEnumerable<string> Authors { get; }
View on GitHub (pinned to 0d5abdd10c)
Solutions
- Verify the file path ends in .nupkg or .nuspec before constructing ChocolateyPackageMetadata
- Check that the path points to an actual file and not a directory
- Ensure packaging build completed successfully and produced the expected .nupkg output
- Add a file extension check: if (!path.EndsWith(".nupkg") && !path.EndsWith(".nuspec")) return error
Example fix
// before
var metadata = new ChocolateyPackageMetadata(@"C:\packages\mytool-1.0.zip");
// after
var metadata = new ChocolateyPackageMetadata(@"C:\packages\mytool-1.0.nupkg");
// defensive check
var path = @"C:\packages\mytool-1.0";
var nupkg = Directory.GetFiles(path, "*.nupkg").FirstOrDefault();
if (nupkg != null)
var metadata = new ChocolateyPackageMetadata(nupkg); Defensive patterns
Strategy: validation
Validate before calling
// Validate file extension before constructing ChocolateyPackageMetadata
var ext = Path.GetExtension(packagePath)?.ToLowerInvariant();
if (ext != ".nupkg" && ext != ".nuspec")
{
throw new ArgumentException($"Expected .nupkg or .nuspec file, got: {packagePath}");
}
if (!File.Exists(packagePath))
{
throw new FileNotFoundException($"Package file not found: {packagePath}");
} Type guard
public static bool IsValidPackageFile(string path)
{
if (string.IsNullOrWhiteSpace(path)) return false;
var ext = Path.GetExtension(path)?.ToLowerInvariant();
return ext == ".nupkg" || ext == ".nuspec";
} Try / catch
try
{
var metadata = new ChocolateyPackageMetadata(packagePath, filesystem);
}
catch (ArgumentException ex) when (ex.Message.Contains(".nupkg or .nuspec"))
{
logger.Error($"Invalid package file: {packagePath}. Must be .nupkg or .nuspec.");
// Find the correct file in the directory
} Prevention
- Always verify the file extension before passing a path to ChocolateyPackageMetadata
- Use Directory.GetFiles(dir, "*.nupkg") to discover valid package files
- Validate File.Exists before construction to catch path errors early
- In CI pipelines, ensure the build produces .nupkg output before attempting metadata extraction
When it happens
Trigger: Passing a path to a .zip, .config, .xml, or any non-.nupkg/.nuspec file to the ChocolateyPackageMetadata constructor. Passing a directory path instead of a file path. Passing a file with no extension. Passing a corrupt path where GetFileExtension returns something unexpected.
Common situations: Automated packaging pipeline passes the wrong file path (e.g. the build output .dll instead of the .nupkg). User renames a .nupkg to .zip for inspection and then accidentally passes the .zip. Script constructs a path by string concatenation and introduces a typo or missing extension. Unpacking step creates intermediate files that get picked up by a glob.
Related errors
- Package name cannot point directly to a local, or remote fil
- Package name cannot point directly to a package manifest fil
- Package name cannot be a path to a file
- No {0} files (or more than 1) were found to build in '{1}'.
- One or more issues found with {0}, please fix all validation
AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13).
Data as JSON: /api/errors/ffdb46b3f4bc1588.
Report an issue: GitHub.