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
- Remove the existing directory at the reported path
- Pass --force to overwrite the existing scaffold
- 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
- Check the output directory does not exist before scaffolding
- Pass --force only when overwriting is intended
- Use a unique package name or a dedicated --output-directory per run
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
- Unable to find path to requested template '{0}'. Path should
- Source '{0}' is unable to be parsed
- Unable to find requested template '{0}'
- Cannot move or delete the root of the system drive
- An exception occurred while copying files to '{0}'
AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13).
Data as JSON: /api/errors/df51cc342aaadb62.
Report an issue: GitHub.