chocolatey/choco · error · ApplicationException

Unable to find path to requested template

Error message

Unable to find path to requested template '{0}'. Path should be '{1}'

What it means

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.

Solutions

  1. Install the template package first (choco install <name>.template)
  2. Verify the exact template folder name under the templates location (case-sensitive on some filesystems)
  3. Check the spelling of the --template value
  4. Omit --template to use the built-in default template

Example fix

// before
choco new mypkg --template=custom
# (custom template not installed)
// after
choco install custom.template
choco new mypkg --template=custom
Defensive patterns

Strategy: validation

Validate before calling

var templateName = string.IsNullOrWhiteSpace(config.NewCommand.TemplateName) ? "default" : config.NewCommand.TemplateName;
var templatePath = fileSystem.CombinePaths(ApplicationParameters.TemplatesLocation, templateName);
if (!fileSystem.DirectoryExists(templatePath)) {
    throw new DirectoryNotFoundException($"Template '{templateName}' not found at '{templatePath}'. Install it first.");
}

Try / catch

try { templateService.Generate(config); }
catch (ApplicationException ex) when (ex.Message.Contains("Unable to find path to requested template")) {
    logger.Error(ex.Message); // install the template package then retry
}

Prevention

When it happens

Trigger: 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.

Common situations: Referencing a template package that was never installed; a typo or wrong case in the template name; templates location differs from the expected path.

Related errors


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

Appendix: source

Thrown at src/chocolatey/infrastructure.app/services/TemplateService.cs:179

            {
                GenerateFileFromTemplate(configuration, tokens, NuspecTemplate.Template, _fileSystem.CombinePaths(packageLocation, "{0}.nuspec".FormatWith(tokens.PackageNameLower)), _utf8WithoutBOM);
                GenerateFileFromTemplate(configuration, tokens, ChocolateyInstallTemplate.Template, _fileSystem.CombinePaths(packageToolsLocation, "chocolateyinstall.ps1"), Encoding.UTF8);
                GenerateFileFromTemplate(configuration, tokens, ChocolateyBeforeModifyTemplate.Template, _fileSystem.CombinePaths(packageToolsLocation, "chocolateybeforemodify.ps1"), Encoding.UTF8);
                GenerateFileFromTemplate(configuration, tokens, ChocolateyUninstallTemplate.Template, _fileSystem.CombinePaths(packageToolsLocation, "chocolateyuninstall.ps1"), Encoding.UTF8);
                GenerateFileFromTemplate(configuration, tokens, ChocolateyLicenseFileTemplate.Template, _fileSystem.CombinePaths(packageToolsLocation, "LICENSE.txt"), Encoding.UTF8);
                GenerateFileFromTemplate(configuration, tokens, ChocolateyVerificationFileTemplate.Template, _fileSystem.CombinePaths(packageToolsLocation, "VERIFICATION.txt"), Encoding.UTF8);
                GenerateFileFromTemplate(configuration, tokens, ChocolateyReadMeTemplate.Template, _fileSystem.CombinePaths(packageLocation, "ReadMe.md"), Encoding.UTF8);
                GenerateFileFromTemplate(configuration, tokens, ChocolateyTodoTemplate.Template, _fileSystem.CombinePaths(packageLocation, "_TODO.txt"), Encoding.UTF8);
            }
            else
            {
                configuration.NewCommand.TemplateName = string.IsNullOrWhiteSpace(configuration.NewCommand.TemplateName) ? "default" : configuration.NewCommand.TemplateName;

                var templatePath = _fileSystem.CombinePaths(ApplicationParameters.TemplatesLocation, configuration.NewCommand.TemplateName);
                var templateParameterCachePath = _fileSystem.CombinePaths(templatePath, _templateParameterCacheFilename);
                if (!_fileSystem.DirectoryExists(templatePath))
                {
                    throw new ApplicationException("Unable to find path to requested template '{0}'. Path should be '{1}'".FormatWith(configuration.NewCommand.TemplateName, templatePath));
                }

                this.Log().Info(configuration.QuietOutput ? logger : ChocolateyLoggers.Important, "Generating package from custom template at '{0}'.".FormatWith(templatePath));

                // Create directory structure from template so as to include empty directories
                foreach (var directory in _fileSystem.GetDirectories(templatePath, "*.*", SearchOption.AllDirectories))
                {
                    var packageDirectoryLocation = directory.Replace(templatePath, packageLocation);
                    this.Log().Debug("Creating directory {0}".FormatWith(packageDirectoryLocation));
                    _fileSystem.EnsureDirectoryExists(packageDirectoryLocation);
                }
                foreach (var file in _fileSystem.GetFiles(templatePath, "*.*", SearchOption.AllDirectories))
                {
                    var packageFileLocation = file.Replace(templatePath, packageLocation);
                    var fileExtension = _fileSystem.GetFileExtension(packageFileLocation);

                    if (fileExtension.IsEqualTo(".nuspec"))
                    {

View on GitHub (pinned to 0d5abdd10c)