{"record":{"id":"1643b7a0e797e800","repo":"chocolatey/choco","slug":"unable-to-find-path-to-requested-template-0-p","errorCode":null,"errorMessage":"Unable to find path to requested template '{0}'. Path should be '{1}'","messagePattern":"Unable to find path to requested template '(.+?)'\\. Path should be '(.+?)'","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/services/TemplateService.cs","lineNumber":179,"sourceCode":"            {\r\n                GenerateFileFromTemplate(configuration, tokens, NuspecTemplate.Template, _fileSystem.CombinePaths(packageLocation, \"{0}.nuspec\".FormatWith(tokens.PackageNameLower)), _utf8WithoutBOM);\r\n                GenerateFileFromTemplate(configuration, tokens, ChocolateyInstallTemplate.Template, _fileSystem.CombinePaths(packageToolsLocation, \"chocolateyinstall.ps1\"), Encoding.UTF8);\r\n                GenerateFileFromTemplate(configuration, tokens, ChocolateyBeforeModifyTemplate.Template, _fileSystem.CombinePaths(packageToolsLocation, \"chocolateybeforemodify.ps1\"), Encoding.UTF8);\r\n                GenerateFileFromTemplate(configuration, tokens, ChocolateyUninstallTemplate.Template, _fileSystem.CombinePaths(packageToolsLocation, \"chocolateyuninstall.ps1\"), Encoding.UTF8);\r\n                GenerateFileFromTemplate(configuration, tokens, ChocolateyLicenseFileTemplate.Template, _fileSystem.CombinePaths(packageToolsLocation, \"LICENSE.txt\"), Encoding.UTF8);\r\n                GenerateFileFromTemplate(configuration, tokens, ChocolateyVerificationFileTemplate.Template, _fileSystem.CombinePaths(packageToolsLocation, \"VERIFICATION.txt\"), Encoding.UTF8);\r\n                GenerateFileFromTemplate(configuration, tokens, ChocolateyReadMeTemplate.Template, _fileSystem.CombinePaths(packageLocation, \"ReadMe.md\"), Encoding.UTF8);\r\n                GenerateFileFromTemplate(configuration, tokens, ChocolateyTodoTemplate.Template, _fileSystem.CombinePaths(packageLocation, \"_TODO.txt\"), Encoding.UTF8);\r\n            }\r\n            else\r\n            {\r\n                configuration.NewCommand.TemplateName = string.IsNullOrWhiteSpace(configuration.NewCommand.TemplateName) ? \"default\" : configuration.NewCommand.TemplateName;\r\n\r\n                var templatePath = _fileSystem.CombinePaths(ApplicationParameters.TemplatesLocation, configuration.NewCommand.TemplateName);\r\n                var templateParameterCachePath = _fileSystem.CombinePaths(templatePath, _templateParameterCacheFilename);\r\n                if (!_fileSystem.DirectoryExists(templatePath))\r\n                {\r\n                    throw new ApplicationException(\"Unable to find path to requested template '{0}'. Path should be '{1}'\".FormatWith(configuration.NewCommand.TemplateName, templatePath));\r\n                }\r\n\r\n                this.Log().Info(configuration.QuietOutput ? logger : ChocolateyLoggers.Important, \"Generating package from custom template at '{0}'.\".FormatWith(templatePath));\r\n\r\n                // Create directory structure from template so as to include empty directories\r\n                foreach (var directory in _fileSystem.GetDirectories(templatePath, \"*.*\", SearchOption.AllDirectories))\r\n                {\r\n                    var packageDirectoryLocation = directory.Replace(templatePath, packageLocation);\r\n                    this.Log().Debug(\"Creating directory {0}\".FormatWith(packageDirectoryLocation));\r\n                    _fileSystem.EnsureDirectoryExists(packageDirectoryLocation);\r\n                }\r\n                foreach (var file in _fileSystem.GetFiles(templatePath, \"*.*\", SearchOption.AllDirectories))\r\n                {\r\n                    var packageFileLocation = file.Replace(templatePath, packageLocation);\r\n                    var fileExtension = _fileSystem.GetFileExtension(packageFileLocation);\r\n\r\n                    if (fileExtension.IsEqualTo(\".nuspec\"))\r\n                    {\r","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/services/TemplateService.cs#L161-L197","documentation":"When generating from a custom template, if the template directory under TemplatesLocation/<TemplateName> does not exist, TemplateService throws ApplicationException with the requested template name and the expected path. The default 'default' fallback is only applied when TemplateName is blank.","triggerScenarios":"Running choco new with a custom --template=<name> where combine(TemplatesLocation, TemplateName) does not exist (DirectoryExists false), and TemplateName was non-empty so it is not defaulted.","commonSituations":"Referencing a template package that was never installed; a typo or wrong case in the template name; templates location differs from the expected path.","solutions":["Install the template package first (choco install <name>.template)","Verify the exact template folder name under the templates location (case-sensitive on some filesystems)","Check the spelling of the --template value","Omit --template to use the built-in default template"],"exampleFix":"// before\nchoco new mypkg --template=custom\n# (custom template not installed)\n// after\nchoco install custom.template\nchoco new mypkg --template=custom","handlingStrategy":"validation","validationCode":"var templateName = string.IsNullOrWhiteSpace(config.NewCommand.TemplateName) ? \"default\" : config.NewCommand.TemplateName;\nvar templatePath = fileSystem.CombinePaths(ApplicationParameters.TemplatesLocation, templateName);\nif (!fileSystem.DirectoryExists(templatePath)) {\n    throw new DirectoryNotFoundException($\"Template '{templateName}' not found at '{templatePath}'. Install it first.\");\n}","typeGuard":null,"tryCatchPattern":"try { templateService.Generate(config); }\ncatch (ApplicationException ex) when (ex.Message.Contains(\"Unable to find path to requested template\")) {\n    logger.Error(ex.Message); // install the template package then retry\n}","preventionTips":["Install template packages (choco install <name>.template) before referencing them","Verify the exact folder name under the templates location (mind case)","Fall back to the default template when a custom one is not required"],"tags":["template","custom-template","filesystem"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}