{"record":{"id":"1d2a1152177f146e","repo":"chocolatey/choco","slug":"package-name-cannot-point-directly-to-a-local-or","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs","lineNumber":1337,"sourceCode":"                {\r\n                    if (Uri.TryCreate(packageName, UriKind.Absolute, out var uri) && (uri.IsFile || uri.IsUnc))\r\n                    {\r\n                        ThrowInvalidPathError(uri.LocalPath, uri.IsUnc, config.CommandName);\r\n                    }\r\n                    else if (_fileSystem.FileExists(packageName))\r\n                    {\r\n                        var fullPath = _fileSystem.GetFullPath(packageName);\r\n\r\n                        if (!string.IsNullOrWhiteSpace(fullPath) && Uri.TryCreate(fullPath, UriKind.Absolute, out uri))\r\n                        {\r\n                            ThrowInvalidPathError(uri.LocalPath, uri.IsUnc, config.CommandName);\r\n                        }\r\n\r\n                        ThrowInvalidPathError(fullPath, isUncPath: false, commandName: config.CommandName);\r\n                    }\r\n                    else\r\n                    {\r\n                        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.\");\r\n\r\n                    }\r\n                }\r\n                else if (packageName.EndsWith(NuGetConstants.ManifestExtension))\r\n                {\r\n                    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.\");\r\n\r\n                }\r\n            }\r\n        }\r\n\r\n        private void ThrowInvalidPathError(string packageName, bool isUncPath, string commandName)\r\n        {\r\n            var sb = new StringBuilder(\"Package name cannot be a path to a file \");\r\n\r\n            if (isUncPath)\r\n            {\r\n                sb.AppendLine(\"on a UNC location.\")\r","sourceCodeStart":1319,"sourceCodeEnd":1355,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs#L1319-L1355","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the --source argument to point to the directory containing the .nupkg file: 'choco install mypackage --source=C:\\packages'.","Pass only the package name (without extension) and specify the directory or UNC path via --source.","For UNC paths, use: 'choco install mypackage --source=\\\\server\\share\\packages'."],"exampleFix":"// before: passing .nupkg file path as package name\nchoco install C:\\packages\\mypackage.1.0.0.nupkg\n\n// after: use --source to point to the directory\nchoco install mypackage --source=C:\\packages\n// or for a UNC path\nchoco install mypackage --source=\\\\server\\share\\packages","handlingStrategy":"validation","validationCode":"// Before calling install/upgrade, validate package names are not .nupkg paths\nforeach (var name in config.PackageNames.Split(';'))\n{\n    if (name.EndsWith(NuGetConstants.PackageExtension, StringComparison.OrdinalIgnoreCase))\n    {\n        // Redirect to --source usage instead of letting the API throw\n        throw new InvalidOperationException(\n            $\"Package name '{name}' looks like a .nupkg file. Use --source to point to the directory: choco install {Path.GetFileNameWithoutExtension(name)} --source={Path.GetDirectoryName(name)}\");\n    }\n}","typeGuard":"public static bool IsValidPackageName(string packageName)\n{\n    return !packageName.EndsWith(\".nupkg\", StringComparison.OrdinalIgnoreCase);\n}","tryCatchPattern":"try\n{\n    _packageService.Install(config);\n}\ncatch (ApplicationException ex) when (ex.Message.Contains(\"Package name cannot point directly to a local, or remote file\"))\n{\n    logger.Error(\"Do not pass .nupkg file paths as package names. Use --source to specify the directory.\");\n}","preventionTips":["Never pass file paths (especially .nupkg) as package names — always use --source for the directory.","Validate that package names consist only of the package ID without path or extension.","For local .nupkg installs use: 'choco install pkgname --source=C:\\path\\to\\dir'."],"tags":["package-name","validation","nupkg","source-argument","chocolatey"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}