chocolatey/choco · error · ApplicationException
Unable to create nupkg. See the log for error details.
Error message
Unable to create nupkg. See the log for error details.
What it means
Thrown as an ApplicationException during Pack when NugetPack.BuildPackage returns false, indicating the .nupkg file could not be created. BuildPackage is the underlying NuGet packaging call that assembles the .nupkg from the manifest and content; a false return signals an internal failure whose details are written to the log but not included in the exception message.
Source
Thrown at src/chocolatey/infrastructure.app/services/NugetService.cs:501
if (!string.IsNullOrWhiteSpace(config.Version))
{
builder.Version = new NuGetVersion(config.Version);
}
var outputFile = builder.Id + "." + builder.Version.ToNormalizedStringChecked() + NuGetConstants.PackageExtension;
var outputFolder = config.OutputDirectory ?? _fileSystem.GetCurrentDirectory();
var outputPath = _fileSystem.CombinePaths(outputFolder, outputFile);
config.Sources = outputFolder;
this.Log().Info(config.QuietOutput ? ChocolateyLoggers.LogFileOnly : ChocolateyLoggers.Normal, () => "Attempting to build package from '{0}'.".FormatWith(_fileSystem.GetFileName(nuspecFilePath)));
_fileSystem.EnsureDirectoryExists(outputFolder);
var createdPackage = NugetPack.BuildPackage(builder, _fileSystem, outputPath);
// package.Validate().Any(v => v.Level == PackageIssueLevel.Error)
if (!createdPackage)
{
throw new ApplicationException("Unable to create nupkg. See the log for error details.");
}
//todo: #602 analyze package
//if (package != null)
//{
// AnalyzePackage(package);
//}
this.Log().Info(config.QuietOutput ? ChocolateyLoggers.LogFileOnly : ChocolateyLoggers.Important, () => "Successfully created package '{0}'".FormatWith(outputPath));
}
public void PushDryRun(ChocolateyConfiguration config)
{
var nupkgFilePath = GetPackageFileOrThrow(config, NuGetConstants.PackageExtension);
this.Log().Info(() => "Would have attempted to push '{0}' to source '{1}'.".FormatWith(_fileSystem.GetFileName(nupkgFilePath), config.Sources));
}
public virtual void Push(ChocolateyConfiguration config)
{
View on GitHub (pinned to 0d5abdd10c)
Solutions
- Check the log output immediately before this error — it contains the specific packaging failure reason.
- Verify all files referenced in the .nuspec <files> section actually exist in the expected locations.
- Ensure write permissions on the output directory.
- Validate metadata fields in the .nuspec (version format, dependency IDs, etc.) against NuGet spec requirements.
- Try packing with increased verbosity: 'choco pack --debug --verbose' to surface the underlying BuildPackage error.
Example fix
// before: pack fails with opaque error choco pack mypackage.nuspec // Error: Unable to create nupkg. See the log for error details. // after: run with debug to find root cause, then fix choco pack mypackage.nuspec --debug --verbose // e.g., fix: add missing content file referenced in nuspec <files> <file src="tools\chocolateyInstall.ps1" target="tools" /> <!-- ensure this file exists --> </files>
Defensive patterns
Strategy: try-catch
Validate before calling
// Before packing, validate the nuspec references files that exist
var nuspecPath = GetPackageFileOrThrow(config, PackagingConstants.ManifestExtension);
ValidateNuspec(nuspecPath, config);
// Additionally, verify all <file> references in the nuspec exist
var nuspecDir = _fileSystem.GetDirectoryName(nuspecPath);
var doc = XDocument.Load(nuspecPath);
var fileElements = doc.Descendants().Where(e => e.Name.LocalName == "file");
foreach (var fe in fileElements)
{
var src = fe.Attribute("src")?.Value;
if (src != null && !_fileSystem.FileExists(_fileSystem.CombinePaths(nuspecDir, src)))
{
throw new InvalidOperationException($"Missing file referenced in nuspec: {src}");
}
} Try / catch
try
{
_nugetService.Pack(config);
}
catch (ApplicationException ex) when (ex.Message.Contains("Unable to create nupkg"))
{
// The root cause is in the log output preceding this exception
logger.Error("Packaging failed. Re-run with --debug --verbose to see the underlying BuildPackage error.");
// Common causes: missing content files, invalid metadata, permission issues
} Prevention
- Always run pack with --debug --verbose when troubleshooting to see the underlying BuildPackage error.
- Verify all files referenced in the .nuspec <files> section exist at the specified paths.
- Ensure write permissions on the output directory.
- Validate metadata fields (version, dependencies, IDs) against NuGet specification requirements before packing.
- Test .nuspec files incrementally — start minimal, add content sections one at a time.
When it happens
Trigger: Inside Pack, after ValidateNuspec succeeds and the output path is computed, NugetPack.BuildPackage(builder, _fileSystem, outputPath) is called. If it returns false (any internal packaging failure — invalid metadata, I/O error, missing content files, builder configuration issue), this exception is thrown.
Common situations: A .nuspec file passes validation but the packaging step fails due to issues like missing content files referenced in the manifest, invalid metadata values rejected by the NuGet builder, file system permission issues writing the .nupkg, or corrupt template data. The actual cause is in the preceding log output.
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}'.
- File specified is either not found or not a {0} file. '{1}'
AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13).
Data as JSON: /api/errors/51cb95b2c4b6aa91.
Report an issue: GitHub.