如何创建默认情况下不提供编号文件名的VisualStudio项目模板 [英] How to create a VisualStudio item template that does not offer numbered file names by default

查看:133
本文介绍了如何创建默认情况下不提供编号文件名的VisualStudio项目模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建默认名称为foo.txt的项目模板,则即使文件夹中没有foo.txt,Visual Studio在默认情况下也会在添加新对话框"中提供名称foo1.txt.

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.

通常可以,但是我需要创建一个项目模板,默认情况下为文件名提供"1"后缀,就像App.config模板一样.

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.

我已经在VS2019安装中检查了App.vstemplate文件,但是我没有看到会导致此行为的任何特殊设置.

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

示例:

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

推荐答案

对不起,但恐怕答案是否定的.我认为这 行为是设计使然,不能由 .vstemplate.

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.

我已经在我这边转载了这个问题.我发现的一件有趣的事是,如果我们将文件扩展名更改为.manifest,此问题就消失了.

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.

例如:

如果我要创建的项目模板类似于foo.manifest而不是foo.txt,那么当我在新项目中添加该项目时,它将不会显示1后缀.您可以通过将所有foo.txt内容更改为foo.manifest来轻松确认这一点.

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.

我同意Will的观点,他们特别强调了某些模板.更具体地说,此行为对于我们创建的Item的文件扩展名是特殊的.创建xxx.manifest Item时,我没有做任何不同的事情,但这与xxx.txt Item有所不同.因此,我认为有一个看不见的未知规则来控制此行为,并且在自定义扩展中可能不会更改或控制此行为.我相信这就像是产品团队设计的规则.

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.

在我看来,当前的VS SDK不支持控制行为,以使VS在文件扩展名为.txt的项目中不显示'1' suffix.如果您确实要使用此功能,请访问开发者社区在那分享您的好主意.实际上,在您提醒之后,最好提供此功能,然后我们可以真的控制Default Name,因此,如果您决定发布想法,则可以在问题中分享链接以及对它感兴趣的成员将有助于投票.

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

这篇关于如何创建默认情况下不提供编号文件名的VisualStudio项目模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆