chocolatey/choco · error · ApplicationException

The location for the template already exists. You can:{0} 1.

Error message

The location for the template already exists. You can:{0} 1. Remove '{1}'{0} 2. Use --force{0} 3. Specify a different name

What it means

TemplateService.Generate throws ApplicationException when the target output directory for the new package already exists and --force was not supplied. The message lists the conflicting path and three resolution options (remove it, use --force, or pick a different name).

Source

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

        public void GenerateDryRun(ChocolateyConfiguration configuration)
        {
            var templateLocation = _fileSystem.CombinePaths(configuration.OutputDirectory ?? _fileSystem.GetCurrentDirectory(), configuration.NewCommand.Name);
            this.Log().Info(() => "Would have generated a new package specification at {0}".FormatWith(templateLocation));
        }

        public void Generate(ChocolateyConfiguration configuration)
        {
            var logger = ChocolateyLoggers.Normal;
            if (configuration.QuietOutput)
            {
                logger = ChocolateyLoggers.LogFileOnly;
            }

            var packageLocation = _fileSystem.CombinePaths(configuration.OutputDirectory ?? _fileSystem.GetCurrentDirectory(), configuration.NewCommand.Name);
            if (_fileSystem.DirectoryExists(packageLocation) && !configuration.Force)
            {
                throw new ApplicationException(
                    "The location for the template already exists. You can:{0} 1. Remove '{1}'{0} 2. Use --force{0} 3. Specify a different name".FormatWith(Environment.NewLine, packageLocation));
            }

            if (configuration.RegularOutput)
            {
                this.Log().Info(logger, () => "Creating a new package specification at {0}".FormatWith(packageLocation));
            }

            try
            {
                _fileSystem.DeleteDirectoryChecked(packageLocation, recursive: true);
            }
            catch (Exception ex)
            {
                if (configuration.RegularOutput)
                {
                    this.Log().Warn(() => "{0}".FormatWith(ex.Message));
                }

View on GitHub (pinned to 0d5abdd10c)

Solutions

  1. Remove the existing directory at the reported path
  2. Pass --force to overwrite the existing scaffold
  3. Specify a different package name or a different --output-directory

Example fix

// before
choco new mypkg
# (directory mypkg already exists)
// after
choco new mypkg --force
Defensive patterns

Strategy: validation

Validate before calling

var packageLocation = fileSystem.CombinePaths(config.OutputDirectory ?? fileSystem.GetCurrentDirectory(), config.NewCommand.Name);
if (fileSystem.DirectoryExists(packageLocation) && !config.Force) {
    throw new IOException($"Output directory '{packageLocation}' exists; remove it, use --force, or rename.");
}

Try / catch

try { templateService.Generate(config); }
catch (ApplicationException ex) when (ex.Message.Contains("template already exists")) {
    logger.Error(ex.Message); // remove dir, set config.Force = true, or rename
}

Prevention

When it happens

Trigger: Running choco new <name> (Generate) where combine(outputDir ?? cwd, NewCommand.Name) already exists as a directory and configuration.Force is false.

Common situations: Re-scaffolding a package that was already generated; default output directory already contains a folder with that name; running new twice by mistake.

Related errors


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