templating icon indicating copy to clipboard operation
templating copied to clipboard

[Epic] Provide mechanism for using defaultName instead of Currentfolder name as fallback if --name is not specified

Open phenning opened this issue 5 years ago • 5 comments

See the following issues for more details:

This impacts https://github.com/dotnet/aspnetcore/issues/11824 and associated PR https://github.com/dotnet/aspnetcore/issues/11824

The relevant areas of templating code are: https://github.com/dotnet/templating/blob/f15388ee6e45a8923fba0f54f55154aee991fb84/src/Microsoft.TemplateEngine.Cli/TemplateInvoker.cs#L153

https://github.com/dotnet/templating/blob/f15388ee6e45a8923fba0f54f55154aee991fb84/src/Microsoft.TemplateEngine.Edge/Template/TemplateCreator.cs#L71

Note that fixing this for the CLI should not regress VS scenarios, but we should be pretty well insulated against that since the IDE passes the actual name as the fallback, and all IDEs always explicitly pass the name: https://github.com/dotnet/templating/blob/f15388ee6e45a8923fba0f54f55154aee991fb84/src/Microsoft.TemplateEngine.IDE/Bootstrapper.cs#L93

phenning avatar Mar 05 '20 18:03 phenning

Investigate whether if we can auto-increment default name, if it ends with digit and the file with default name already exist.

vlada-shubina avatar Oct 20 '20 16:10 vlada-shubina

For what its worth, in the Visual Studio host we strip off any trailing digits on the default name before passing it to the IDE for use in the New project dialog, since the new project dialog requires for there not to be trailing digits to increment property - it assumes that any trailing digits are "fixed".

phenning avatar Oct 26 '20 16:10 phenning

@phenning we discussed the following approach for default name:

  • we would still use the name of the current folder as default option
  • we would introduce another property to template.json configuration, similar to preferDefaultName: in case set to true default name will be used instead of the current folder.

As we understand the use case of https://github.com/dotnet/aspnetcore/issues/11824 it's more applicable to item templates, and default name would be something similar to Class1. User might want to use dotnet new to create multiple items, and then second attempt may fail due to file(s) already exist. Auto-increment might be useful to avoid this failure, moreover it would be similar to VS behavior, however on the other hand probably the user will pick up non-default name for these items.

For now it's just an idea, if it's too complicated we might drop it.

vlada-shubina avatar Oct 26 '20 17:10 vlada-shubina

Agreed not to implement auto-increment of default name as part of current issue. defaultName will be enabled to be used if preferDefaultName is set to true. In case preferDefaultName is false or missing current directory name will be used.

vlada-shubina avatar Nov 03 '20 17:11 vlada-shubina

Just came across with this issue. Considering that defaultName automatically enriches the Project Name input when creating a project from Visual Studio UI, I would expect a similar behavior in the CLI.

It would be nice to have this implemented, as currently users are forced to use --name | -n.

tiagojsrios avatar Jul 11 '22 14:07 tiagojsrios