{"record":{"id":"51cb95b2c4b6aa91","repo":"chocolatey/choco","slug":"unable-to-create-nupkg-see-the-log-for-error-deta","errorCode":null,"errorMessage":"Unable to create nupkg. See the log for error details.","messagePattern":"Unable to create nupkg\\. See the log for error details\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/services/NugetService.cs","lineNumber":501,"sourceCode":"            if (!string.IsNullOrWhiteSpace(config.Version))\r\n            {\r\n                builder.Version = new NuGetVersion(config.Version);\r\n            }\r\n\r\n            var outputFile = builder.Id + \".\" + builder.Version.ToNormalizedStringChecked() + NuGetConstants.PackageExtension;\r\n            var outputFolder = config.OutputDirectory ?? _fileSystem.GetCurrentDirectory();\r\n            var outputPath = _fileSystem.CombinePaths(outputFolder, outputFile);\r\n\r\n            config.Sources = outputFolder;\r\n\r\n            this.Log().Info(config.QuietOutput ? ChocolateyLoggers.LogFileOnly : ChocolateyLoggers.Normal, () => \"Attempting to build package from '{0}'.\".FormatWith(_fileSystem.GetFileName(nuspecFilePath)));\r\n            _fileSystem.EnsureDirectoryExists(outputFolder);\r\n\r\n            var createdPackage = NugetPack.BuildPackage(builder, _fileSystem, outputPath);\r\n            // package.Validate().Any(v => v.Level == PackageIssueLevel.Error)\r\n            if (!createdPackage)\r\n            {\r\n                throw new ApplicationException(\"Unable to create nupkg. See the log for error details.\");\r\n            }\r\n            //todo: #602 analyze package\r\n            //if (package != null)\r\n            //{\r\n            //    AnalyzePackage(package);\r\n            //}\r\n\r\n            this.Log().Info(config.QuietOutput ? ChocolateyLoggers.LogFileOnly : ChocolateyLoggers.Important, () => \"Successfully created package '{0}'\".FormatWith(outputPath));\r\n        }\r\n\r\n        public void PushDryRun(ChocolateyConfiguration config)\r\n        {\r\n            var nupkgFilePath = GetPackageFileOrThrow(config, NuGetConstants.PackageExtension);\r\n            this.Log().Info(() => \"Would have attempted to push '{0}' to source '{1}'.\".FormatWith(_fileSystem.GetFileName(nupkgFilePath), config.Sources));\r\n        }\r\n\r\n        public virtual void Push(ChocolateyConfiguration config)\r\n        {\r","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/services/NugetService.cs#L483-L519","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: pack fails with opaque error\nchoco pack mypackage.nuspec\n// Error: Unable to create nupkg. See the log for error details.\n\n// after: run with debug to find root cause, then fix\nchoco pack mypackage.nuspec --debug --verbose\n// e.g., fix: add missing content file referenced in nuspec\n<files>\n  <file src=\"tools\\chocolateyInstall.ps1\" target=\"tools\" />\n  <!-- ensure this file exists -->\n</files>","handlingStrategy":"try-catch","validationCode":"// Before packing, validate the nuspec references files that exist\nvar nuspecPath = GetPackageFileOrThrow(config, PackagingConstants.ManifestExtension);\nValidateNuspec(nuspecPath, config);\n// Additionally, verify all <file> references in the nuspec exist\nvar nuspecDir = _fileSystem.GetDirectoryName(nuspecPath);\nvar doc = XDocument.Load(nuspecPath);\nvar fileElements = doc.Descendants().Where(e => e.Name.LocalName == \"file\");\nforeach (var fe in fileElements)\n{\n    var src = fe.Attribute(\"src\")?.Value;\n    if (src != null && !_fileSystem.FileExists(_fileSystem.CombinePaths(nuspecDir, src)))\n    {\n        throw new InvalidOperationException($\"Missing file referenced in nuspec: {src}\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    _nugetService.Pack(config);\n}\ncatch (ApplicationException ex) when (ex.Message.Contains(\"Unable to create nupkg\"))\n{\n    // The root cause is in the log output preceding this exception\n    logger.Error(\"Packaging failed. Re-run with --debug --verbose to see the underlying BuildPackage error.\");\n    // Common causes: missing content files, invalid metadata, permission issues\n}","preventionTips":["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."],"tags":["pack","nupkg","buildpackage","application","chocolatey"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}