chocolatey/choco · error · ApplicationException

Package name cannot point directly to a package manifest fil

Error message

Package name cannot point directly to a package manifest file. Please create a package by running 'choco pack' on the .nuspec file first.

What it means

Thrown as an ApplicationException during ValidatePackageNames when a package name ends with '.nuspec' (NuGetConstants.ManifestExtension). A .nuspec is a package manifest/source file — it must first be packed into a .nupkg using 'choco pack' before it can be installed. Passing a .nuspec directly as a package name to install/upgrade/uninstall is unsupported.

Source

Thrown at src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs:1343

                    {
                        var fullPath = _fileSystem.GetFullPath(packageName);

                        if (!string.IsNullOrWhiteSpace(fullPath) && Uri.TryCreate(fullPath, UriKind.Absolute, out uri))
                        {
                            ThrowInvalidPathError(uri.LocalPath, uri.IsUnc, config.CommandName);
                        }

                        ThrowInvalidPathError(fullPath, isUncPath: false, commandName: config.CommandName);
                    }
                    else
                    {
                        throw new ApplicationException("Package name cannot point directly to a local, or remote file. Please use the --source argument and point it to a local file directory, UNC directory path or a NuGet feed instead.");

                    }
                }
                else if (packageName.EndsWith(NuGetConstants.ManifestExtension))
                {
                    throw new ApplicationException("Package name cannot point directly to a package manifest file. Please create a package by running 'choco pack' on the .nuspec file first.");

                }
            }
        }

        private void ThrowInvalidPathError(string packageName, bool isUncPath, string commandName)
        {
            var sb = new StringBuilder("Package name cannot be a path to a file ");

            if (isUncPath)
            {
                sb.AppendLine("on a UNC location.")
                  .AppendLine()
                  .Append("To ")
                  .Append(commandName.ToLowerSafe())
                  .AppendLine(" a file in a UNC location, you may use:");
            }
            else

View on GitHub (pinned to 0d5abdd10c)

Solutions

  1. Pack the .nuspec into a .nupkg first: 'choco pack mypackage.nuspec'.
  2. Then install from the directory containing the packed .nupkg: 'choco install mypackage --source=C:\build\output'.
  3. If the .nuspec is in the current directory, run 'choco pack' then 'choco install mypackage --source=.'.

Example fix

// before: trying to install directly from a manifest
choco install mypackage.nuspec

// after: pack first, then install
choco pack mypackage.nuspec
choco install mypackage --source=.
Defensive patterns

Strategy: validation

Validate before calling

// Before calling install/upgrade, validate package names are not .nuspec files
foreach (var name in config.PackageNames.Split(';'))
{
    if (name.EndsWith(NuGetConstants.ManifestExtension, StringComparison.OrdinalIgnoreCase))
    {
        throw new InvalidOperationException(
            $"'{name}' is a .nuspec manifest. Pack it first with 'choco pack {name}', then install from the output directory.");
    }
}

Type guard

public static bool IsValidPackageName(string packageName)
{
    return !packageName.EndsWith(".nuspec", StringComparison.OrdinalIgnoreCase);
}

Try / catch

try
{
    _packageService.Install(config);
}
catch (ApplicationException ex) when (ex.Message.Contains("package manifest file"))
{
    logger.Error("Cannot install .nuspec directly. Run 'choco pack' first to create a .nupkg.");
}

Prevention

When it happens

Trigger: Calling install/upgrade/uninstall with config.PackageNames containing a value ending in '.nuspec'. The code checks the extension immediately after the .nupkg branch and throws unconditionally for .nuspec files.

Common situations: A user runs 'choco install mypackage.nuspec' or 'choco install .\mypackage.nuspec' trying to install from a manifest. They need to pack it first: 'choco pack mypackage.nuspec' produces a .nupkg which can then be installed via --source.

Related errors


AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13). Data as JSON: /api/errors/e34db8a7d600c6be. Report an issue: GitHub.