chocolatey/choco · error · FileNotFoundException
No {0} files (or more than 1) were found to build in '{1}'.
Error message
No {0} files (or more than 1) were found to build in '{1}'. Please specify the {0} file or try in a different directory. What it means
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.
Source
Thrown at src/chocolatey/infrastructure.app/services/NugetService.cs:430
}
}
public void PackDryRun(ChocolateyConfiguration config)
{
this.Log().Info("{0} would have searched for a nuspec file in \"{1}\" and attempted to compile it.".FormatWith(
ApplicationParameters.Name,
config.OutputDirectory ?? _fileSystem.GetCurrentDirectory()
));
}
public virtual string GetPackageFileOrThrow(ChocolateyConfiguration config, string extension)
{
Func<IFileSystem, string> getLocalFiles = (fileSystem) =>
{
var filesFound = fileSystem.GetFiles(fileSystem.GetCurrentDirectory(), "*" + extension).ToList().OrEmpty();
Ensure.That(() => filesFound)
.Meets((files) => files.Count() == 1,
(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())); });
return filesFound.FirstOrDefault();
};
var filePath = !string.IsNullOrWhiteSpace(config.Input) ? config.Input : getLocalFiles.Invoke(_fileSystem);
Ensure.That(() => filePath).Meets((file) => _fileSystem.GetFileExtension(file).IsEqualTo(extension) && _fileSystem.FileExists(file),
(name, value) => { throw new ArgumentException("File specified is either not found or not a {0} file. '{1}'".FormatWith(extension, value)); });
return filePath;
}
public virtual void Pack(ChocolateyConfiguration config)
{
var nuspecFilePath = GetPackageFileOrThrow(config, PackagingConstants.ManifestExtension);
ValidateNuspec(nuspecFilePath, config);
var nuspecDirectory = _fileSystem.GetFullPath(_fileSystem.GetDirectoryName(nuspecFilePath));
if (string.IsNullOrWhiteSpace(nuspecDirectory))
View on GitHub (pinned to 0d5abdd10c)
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.
Example fix
// before: multiple .nuspec files in directory, auto-discovery fails > dir packageA.nuspec packageB.nuspec choco pack // throws // after: specify the file explicitly choco pack packageA.nuspec
Defensive patterns
Strategy: validation
Validate before calling
// Before calling GetPackageFileOrThrow, verify file count in directory
if (string.IsNullOrWhiteSpace(config.Input))
{
var matchingFiles = _fileSystem
.GetFiles(_fileSystem.GetCurrentDirectory(), "*" + extension)
.ToList();
if (matchingFiles.Count != 1)
{
throw new InvalidOperationException(
matchingFiles.Count == 0
? $"No *{extension} files found in '{_fileSystem.GetCurrentDirectory()}'. Specify the file explicitly."
: $"Multiple *{extension} files found. Specify which file to use via the input parameter.");
}
} Try / catch
try
{
var packageFile = _nugetService.GetPackageFileOrThrow(config, extension);
}
catch (FileNotFoundException ex) when (ex.Message.Contains("No ") || ex.Message.Contains("more than 1"))
{
logger.Error($"Expected exactly one {extension} file. " + ex.Message);
// Suggest specifying the file explicitly
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Package name cannot point directly to a package manifest fil
- File specified is either not found or not a {0} file. '{1}'
- One or more issues found with {0}, please fix all validation
- When specifying the subcommand '{0}', you must also specify
- No rule with the name {0} could be found.
AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13).
Data as JSON: /api/errors/e8f944b24d0ff4cd.
Report an issue: GitHub.