chocolatey/choco · error · ApplicationException

Package name cannot point directly to a local, or remote fil

Error message

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.

What it means

Thrown as an ApplicationException during ValidatePackageNames when a package name ends with '.nupkg' (NuGetConstants.PackageExtension) but does not resolve to an actual file on disk (neither a valid absolute file/UNC URI nor a file that _fileSystem.FileExists can find). The user passed what looks like a .nupkg path as a package name, but Chocolatey requires using --source to point to a directory or feed, not passing a file path as the package name.

Source

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

                {
                    if (Uri.TryCreate(packageName, UriKind.Absolute, out var uri) && (uri.IsFile || uri.IsUnc))
                    {
                        ThrowInvalidPathError(uri.LocalPath, uri.IsUnc, config.CommandName);
                    }
                    else if (_fileSystem.FileExists(packageName))
                    {
                        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.")

View on GitHub (pinned to 0d5abdd10c)

Solutions

  1. Use the --source argument to point to the directory containing the .nupkg file: 'choco install mypackage --source=C:\packages'.
  2. Pass only the package name (without extension) and specify the directory or UNC path via --source.
  3. For UNC paths, use: 'choco install mypackage --source=\\server\share\packages'.

Example fix

// before: passing .nupkg file path as package name
choco install C:\packages\mypackage.1.0.0.nupkg

// after: use --source to point to the directory
choco install mypackage --source=C:\packages
// or for a UNC path
choco install mypackage --source=\\server\share\packages
Defensive patterns

Strategy: validation

Validate before calling

// Before calling install/upgrade, validate package names are not .nupkg paths
foreach (var name in config.PackageNames.Split(';'))
{
    if (name.EndsWith(NuGetConstants.PackageExtension, StringComparison.OrdinalIgnoreCase))
    {
        // Redirect to --source usage instead of letting the API throw
        throw new InvalidOperationException(
            $"Package name '{name}' looks like a .nupkg file. Use --source to point to the directory: choco install {Path.GetFileNameWithoutExtension(name)} --source={Path.GetDirectoryName(name)}");
    }
}

Type guard

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

Try / catch

try
{
    _packageService.Install(config);
}
catch (ApplicationException ex) when (ex.Message.Contains("Package name cannot point directly to a local, or remote file"))
{
    logger.Error("Do not pass .nupkg file paths as package names. Use --source to specify the directory.");
}

Prevention

When it happens

Trigger: Calling install/upgrade/uninstall with config.PackageNames containing a value ending in '.nupkg' that is not detected as an existing file path. The code checks Uri.TryCreate for file/UNC URIs, then _fileSystem.FileExists; if neither matches, this generic exception is thrown instead of the more specific ThrowInvalidPathError path.

Common situations: A user runs 'choco install mypackage.nupkg' expecting Chocolatey to install from that local file. The correct approach is 'choco install mypackage --source=C:\path\to\folder'. This error fires when the .nupkg file cannot be resolved to a valid path.

Related errors


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