目前,我正在使用和实例项目(.cft )和方法AddFromFile(".cft")向我的Visual项目添加一个自定义文件类型(例如,.cft)。
不,我的问题是如何告诉Visual对所有.cft文件使用标准.cft编辑器,以及如何为所有.cft文件(解决方案资源管理器)分配图标。
注意,如果使用以下代码产生了差异,则还将为文件分配一个自定义工具:
var vsProjItem = projectItem.Object as VSProjectItem;
pitem.Properties.Item("CustomTool").Value = "MyCustomToolName";发布于 2014-07-07 11:29:04
我认为您需要创建一个具有以下结构的新ItemTemplate:
__TemplateIcon.ico
YourTemplateName.vstemplate [Compile it as vstemplate]
YourFile.cft下面的结构应该生成一个*.zip文件,然后将该文件放在Visual模板文件夹中,然后通过EnvDTE引用该文件。
这是YourTemplateName.vstemplate:
<VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<DefaultName>YourTemplateNameblah</DefaultName>
<Name>Blahblahblah</Name>
<Description>BlahBlahBlah</Description>
<Icon>__TemplateIcon.ico</Icon>
<ProjectType>?? Your project type ??</ProjectType>
<SortOrder>10</SortOrder>
</TemplateData>
<TemplateContent>
<References />
<ProjectItem SubType="Xml" TargetFileName="$fileinputname$.cft" ReplaceParameters="true">YourFile.cft</ProjectItem>
</TemplateContent>
</VSTemplate>MZTOOLS的报价
VisualBasic在“新建项目”对话框中显示的项目模板存储在文件夹C:\ programming (x86)\Microsoft \Common7\IDE\ItemTemplatesCache中,它们存储在包含编程语言("CSharp“、"VisualBasic”等)、技术("Web“、”云“等)的文件夹中。和地区("1033“等) 自动化模型(EnvDTE,EnvDTE80)提供EnvDTE80.Solution2.GetProjectItemTemplate方法来获得一个项目项目模板文件名,给定项目项模板名(例如"Class")和编程语言(如"CSharp“或"VisualBasic")。 有了模板文件名之后,可以使用ProjectItems方法向AddFromTemplate集合添加项目项。注意:此方法返回null (Nothing)而不是创建的EnvDTE.ProjectItem,因此您可能需要在ProjectItems集合中定位创建的项目项。参见PRB: Solution.AddXXX和ProjectItems.AddXXX方法不返回任何内容(null)。
http://www.mztools.com/articles/2014/MZ2014009.aspx
https://stackoverflow.com/questions/24590267
复制相似问题