How to create a VisualStudio item template that does not offer numbered file names by default

一笑奈何 提交于 2020-06-27 13:07:30

问题


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:


回答1:


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.

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:)



来源:https://stackoverflow.com/questions/56856878/how-to-create-a-visualstudio-item-template-that-does-not-offer-numbered-file-nam

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!