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}
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.