4

If I create an item template with default name foo.txt, Visual Studio by default offers the name foo1.txt in the add new dialog, even if there is no foo.txt in the folder.

This is normally fine, but I would need to create an item template, that does not offer a "1" suffix for the file name by default, exactly like the App.config template behaves.

I have checked the App.vstemplate file in the VS2019 installation, but I don't see any special setting that would cause this behavior.

Sample:

<?xml version="1.0" encoding="utf-8"?>
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
  <TemplateData>
    <DefaultName>foo.txt</DefaultName>
    <Name>Foo.txt file</Name>
    <Description>A foo.txt.</Description>
    <ProjectType>CSharp</ProjectType>
  </TemplateData>
  <TemplateContent>
    <ProjectItem>foo.txt</ProjectItem>
  </TemplateContent>
</VSTemplate>

Shows in the add new dialog as: enter image description here

Gaspar Nagy
  • 4,422
  • 30
  • 42
  • I've not seen that behavior before. Could you add a minimal example of an item template that repros this behavior? –  Jul 02 '19 at 16:59
  • I have added an example, but basically almost all of the item templates work like that, except App.config and App.manifest and maybe a few others. – Gaspar Nagy Jul 02 '19 at 18:06
  • Hmmm, you're right. Do you think it's possible that they're special casing some of the templates? app/web.config wouldn't work if folks didn't realize that integer tacked on the end would make the file useless. I don't see anything you're doing differently here that should make a difference. The docs don't look promising, either. I'd consider opening a connect with MS about this, unfortunately. –  Jul 03 '19 at 20:33
  • 1
    Yes, seems like it is a built-in behavior for some specific names/extensions. I will open a case. – Gaspar Nagy Jul 04 '19 at 07:44

1 Answers1

2

Sorry but I'm afraid the answer would be negative. I think this behavior is by design and can't be controlled by any Element in the .vstemplate.

I've reproduced this issue in my side. And one interesting thing I found is if we change the file extensions to .manifest and this issue goes away.

For example:

If the Item template I want to create is something like a foo.manifest instead of foo.txt, then when I add this item in new project it won't display the 1 suffix. You can easily confirm this point by change all your foo.txt content to foo.manifest.

enter image description here

I agree with Will that they're special casing some of the templates. And to be more specific, this behavior is special for the file extensions of the Item we created. I haven't done anything differently when creating xxx.manifest Item, but it just makes a difference from the xxx.txt Item. So I would think there is a invisible and unknown rule to control this behavior, and this behavior may not be changed or controlled in custom extension. It would be something like a rule designed by the Product Team I believe.

In my opinion, it's not supported by current VS SDK to control the behavior to let VS won't display '1' suffix for item whose file extension is .txt. And if you do want this feature, go Developer Community to share your great idea there. Actually after your reminder, it would be better if this feature comes then we can really control the Default Name, so if you decide to post your idea, share the link in your question and members interested in it would help vote for it.

Hope it helps and if i misunderstand anything, feel free to let me know:)

Community
  • 1
  • 1
LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Thx. It is clear and this is what my suspicion was. In my case this is important, because I would like to use the template for adding a config file for a tool (SpecFlow) that expects a specific config file name by convention (specflow.json). I will post a request for the dev community and link it here. – Gaspar Nagy Jul 04 '19 at 07:42
  • Glad to know it makes some help:) – LoLance Jul 04 '19 at 08:39