0

When I go to "Add New Item" in VisualStudio and choose my custom item template (and also with the default item templates) the default entry for the name is XY1.cs, always having the 1 in the end, although the 1 is not given in the vstemplate file.

So as far as I know VS increments this number if an element with the same name already exists.

But why does it start with 1 and is not left out? And can I prevent VS from adding the 1 in my custom template? I want to add an additional string to the given name in my template but often the user does not remove the 1 or does just oversee it, so it results in {WantedFilename}1{AdditionalString}

Creepin
  • 482
  • 4
  • 20

1 Answers1

0

According to Mark Wilson-Thomas, Senior Program Manager, Visual Studio IDE Team on MSDN Blog

Creating through the File-New Item dialog adds a “1” To the filename If you use the File-New Item dialog route to create your EditorConfig, in Visual Studio versions prior to 15.8 Preview 4, you’ll need to manually remove the superfluous “1” Prefixing the EditorConfig file name in the dialog. This is fixed in the 15.8 Preview 4 release.

Update

This announcement seems to only apply to .editorconfig files (and some others like .manifest)

See How to create a VisualStudio item template that does not offer numbered file names by default for more info.

Creepin
  • 482
  • 4
  • 20
  • Does this VS change (regarding the EditorConfig) help in case of a custom item template? – Tz_ Jun 08 '20 at 20:31
  • I am currently not working with VS but I suppose it does, would be weird if it only fixes it for editorconfig files. Just try it. – Creepin Jun 09 '20 at 07:11
  • Apparently this is not a public feature that would be available for custom item templates. VS seems to handle some built-in templates/extensions specially. See the tests and discussions in this thread: https://stackoverflow.com/questions/56856878/how-to-create-a-visualstudio-item-template-that-does-not-offer-numbered-file-nam – Tz_ Jun 09 '20 at 15:50
  • Interesting. Then I think it won't change in the near future :D – Creepin Jun 09 '20 at 16:40