{"record":{"id":"df51cc342aaadb62","repo":"chocolatey/choco","slug":"the-location-for-the-template-already-exists-you","errorCode":null,"errorMessage":"The location for the template already exists. You can:{0} 1. Remove '{1}'{0} 2. Use --force{0} 3. Specify a different name","messagePattern":"The location for the template already exists\\. You can:(.+?) 1\\. Remove '(.+?)'(.+?) 2\\. Use --force(.+?) 3\\. Specify a different name","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/services/TemplateService.cs","lineNumber":79,"sourceCode":"\r\n        public void GenerateDryRun(ChocolateyConfiguration configuration)\r\n        {\r\n            var templateLocation = _fileSystem.CombinePaths(configuration.OutputDirectory ?? _fileSystem.GetCurrentDirectory(), configuration.NewCommand.Name);\r\n            this.Log().Info(() => \"Would have generated a new package specification at {0}\".FormatWith(templateLocation));\r\n        }\r\n\r\n        public void Generate(ChocolateyConfiguration configuration)\r\n        {\r\n            var logger = ChocolateyLoggers.Normal;\r\n            if (configuration.QuietOutput)\r\n            {\r\n                logger = ChocolateyLoggers.LogFileOnly;\r\n            }\r\n\r\n            var packageLocation = _fileSystem.CombinePaths(configuration.OutputDirectory ?? _fileSystem.GetCurrentDirectory(), configuration.NewCommand.Name);\r\n            if (_fileSystem.DirectoryExists(packageLocation) && !configuration.Force)\r\n            {\r\n                throw new ApplicationException(\r\n                    \"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));\r\n            }\r\n\r\n            if (configuration.RegularOutput)\r\n            {\r\n                this.Log().Info(logger, () => \"Creating a new package specification at {0}\".FormatWith(packageLocation));\r\n            }\r\n\r\n            try\r\n            {\r\n                _fileSystem.DeleteDirectoryChecked(packageLocation, recursive: true);\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                if (configuration.RegularOutput)\r\n                {\r\n                    this.Log().Warn(() => \"{0}\".FormatWith(ex.Message));\r\n                }\r","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/services/TemplateService.cs#L61-L97","documentation":"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).","triggerScenarios":"Running choco new <name> (Generate) where combine(outputDir ?? cwd, NewCommand.Name) already exists as a directory and configuration.Force is false.","commonSituations":"Re-scaffolding a package that was already generated; default output directory already contains a folder with that name; running new twice by mistake.","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"],"exampleFix":"// before\nchoco new mypkg\n# (directory mypkg already exists)\n// after\nchoco new mypkg --force","handlingStrategy":"validation","validationCode":"var packageLocation = fileSystem.CombinePaths(config.OutputDirectory ?? fileSystem.GetCurrentDirectory(), config.NewCommand.Name);\nif (fileSystem.DirectoryExists(packageLocation) && !config.Force) {\n    throw new IOException($\"Output directory '{packageLocation}' exists; remove it, use --force, or rename.\");\n}","typeGuard":null,"tryCatchPattern":"try { templateService.Generate(config); }\ncatch (ApplicationException ex) when (ex.Message.Contains(\"template already exists\")) {\n    logger.Error(ex.Message); // remove dir, set config.Force = true, or rename\n}","preventionTips":["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"],"tags":["template","new-package","filesystem"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}