{"record":{"id":"e8f944b24d0ff4cd","repo":"chocolatey/choco","slug":"no-0-files-or-more-than-1-were-found-to-build","errorCode":null,"errorMessage":"No {0} files (or more than 1) were found to build in '{1}'. Please specify the {0} file or try in a different directory.","messagePattern":"No (.+?) files \\(or more than 1\\) were found to build in '(.+?)'\\. Please specify the (.+?) file or try in a different directory\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/services/NugetService.cs","lineNumber":430,"sourceCode":"            }\r\n        }\r\n\r\n        public void PackDryRun(ChocolateyConfiguration config)\r\n        {\r\n            this.Log().Info(\"{0} would have searched for a nuspec file in \\\"{1}\\\" and attempted to compile it.\".FormatWith(\r\n                ApplicationParameters.Name,\r\n                config.OutputDirectory ?? _fileSystem.GetCurrentDirectory()\r\n                                ));\r\n        }\r\n\r\n        public virtual string GetPackageFileOrThrow(ChocolateyConfiguration config, string extension)\r\n        {\r\n            Func<IFileSystem, string> getLocalFiles = (fileSystem) =>\r\n                {\r\n                    var filesFound = fileSystem.GetFiles(fileSystem.GetCurrentDirectory(), \"*\" + extension).ToList().OrEmpty();\r\n                    Ensure.That(() => filesFound)\r\n                          .Meets((files) => files.Count() == 1,\r\n                                 (name, value) => { throw new FileNotFoundException(\"No {0} files (or more than 1) were found to build in '{1}'. Please specify the {0} file or try in a different directory.\".FormatWith(extension, _fileSystem.GetCurrentDirectory())); });\r\n\r\n                    return filesFound.FirstOrDefault();\r\n                };\r\n\r\n            var filePath = !string.IsNullOrWhiteSpace(config.Input) ? config.Input : getLocalFiles.Invoke(_fileSystem);\r\n            Ensure.That(() => filePath).Meets((file) => _fileSystem.GetFileExtension(file).IsEqualTo(extension) && _fileSystem.FileExists(file),\r\n                                              (name, value) => { throw new ArgumentException(\"File specified is either not found or not a {0} file. '{1}'\".FormatWith(extension, value)); });\r\n\r\n            return filePath;\r\n        }\r\n\r\n        public virtual void Pack(ChocolateyConfiguration config)\r\n        {\r\n            var nuspecFilePath = GetPackageFileOrThrow(config, PackagingConstants.ManifestExtension);\r\n            ValidateNuspec(nuspecFilePath, config);\r\n\r\n            var nuspecDirectory = _fileSystem.GetFullPath(_fileSystem.GetDirectoryName(nuspecFilePath));\r\n            if (string.IsNullOrWhiteSpace(nuspecDirectory))\r","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/services/NugetService.cs#L412-L448","documentation":"Thrown as a FileNotFoundException from GetPackageFileOrThrow when the current directory contains zero files matching the specified extension, or more than one matching file. The Ensure.That lambda checks files.Count() == 1 and throws if the count is anything else. This is used by Pack and other commands to auto-discover a single .nuspec or .nupkg file.","triggerScenarios":"Calling GetPackageFileOrThrow (typically via Pack) when config.Input is empty and the current directory either has no files matching '*{extension}' (e.g., no .nuspec files) or has multiple matching files. The extension parameter is typically PackagingConstants.ManifestExtension (.nuspec) for pack operations.","commonSituations":"Running 'choco pack' in a directory with zero .nuspec files (wrong directory), or in a directory with multiple .nuspec files (ambiguous). The user must either navigate to the correct directory or specify the file explicitly via config.Input.","solutions":["If multiple files exist, specify the file explicitly: 'choco pack specific-package.nuspec'.","If no files exist, navigate to the directory containing your .nuspec file or create one.","Ensure only one .nuspec file exists in the working directory if you rely on auto-discovery.","Pass the file path via the config.Input parameter or command-line positional argument."],"exampleFix":"// before: multiple .nuspec files in directory, auto-discovery fails\n> dir\n  packageA.nuspec\n  packageB.nuspec\nchoco pack  // throws\n\n// after: specify the file explicitly\nchoco pack packageA.nuspec","handlingStrategy":"validation","validationCode":"// Before calling GetPackageFileOrThrow, verify file count in directory\nif (string.IsNullOrWhiteSpace(config.Input))\n{\n    var matchingFiles = _fileSystem\n        .GetFiles(_fileSystem.GetCurrentDirectory(), \"*\" + extension)\n        .ToList();\n    if (matchingFiles.Count != 1)\n    {\n        throw new InvalidOperationException(\n            matchingFiles.Count == 0\n                ? $\"No *{extension} files found in '{_fileSystem.GetCurrentDirectory()}'. Specify the file explicitly.\"\n                : $\"Multiple *{extension} files found. Specify which file to use via the input parameter.\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var packageFile = _nugetService.GetPackageFileOrThrow(config, extension);\n}\ncatch (FileNotFoundException ex) when (ex.Message.Contains(\"No \") || ex.Message.Contains(\"more than 1\"))\n{\n    logger.Error($\"Expected exactly one {extension} file. \" + ex.Message);\n    // Suggest specifying the file explicitly\n}","preventionTips":["Ensure exactly one .nuspec file exists in the working directory, or specify it explicitly via config.Input.","Navigate to the correct directory before running 'choco pack'.","List directory contents before running pack to verify file count."],"tags":["pack","nuspec","file-discovery","filenotfound","validation","chocolatey"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}