VSX:仅限 ProjectFlavor 的项目 VSTemplates?
在 Visual Studio 2005、2008 和 2010 中,是否可以定义仅出现在特定 ProjectFlavor 项目的“添加项”对话框中的项模板?如果可以的话,我不想弄乱所有其他不相关项目的“添加项目”对话框。
似乎
是一个固定枚举,我找不到任何放置 ProjectFlavor guid 或其他内容的位置。
我没有看到任何其他产品表现出这种克制的例子,但我想确定一下。
=====
好吧,亚伦的建议很有希望,但我的第一次尝试没有成功。
在 .vstemplate 中:
<TemplateData>
<Name>MyProject A File</Name>
<Description>MyProject A File to do stuff</Description>
<Icon>A.ico</Icon>
<TemplateID>TemplateID_A</TemplateID>
<TemplateGroupID>MyTemplateGroupID</TemplateGroupID>
<ProjectType>CSharp</ProjectType>
<RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
<SortOrder>20</SortOrder>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
<DefaultName>Template_A.cs</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<ShowByDefault>false</ShowByDefault>
</TemplateData>
<TemplateContent>
<ProjectItem ReplaceParameters="true">Template_A.cs</ProjectItem>
</TemplateContent>
在 package.cs 中:
// [ProvideProjectItem(typeof(MyProjectFactory), "MyTemplateGroupID",
// @"Templates\ProjectItems", 600)] // Took this out.
[ProvideProjectFactory(typeof(MyProjectFactory),
"My Project", "My Project Files (*.csproj);*.csproj",
null, null, @"Templates\Projects",
LanguageVsTemplate = "CSharp",
NewProjectRequireNewFolderVsTemplate = true,
TemplateGroupIDsVsTemplate="MyTemplateGroupID",
TemplateIDsVsTemplate = "TemplateID_A,TemplateID_B")]
public sealed class MyPackage : Package { ... }
In Visual Studio 2005, 2008, and 2010, is it possible to define an Item Template that only appears in the Add Item dialog for projects of a particular ProjectFlavor? I'd rather not clutter all of the other unrelated projects' Add Items dialog if I can help it.
Seems that the <ProjectType>CSharp</ProjectType>
is a fixed enumeration and I can't find any place for a ProjectFlavor guid or otherwise.
I don't see any examples of other products showing such restraint, but I want to make sure.
=====
OK, Aaron's tip is very promising but my first attempt is unsuccessful.
In the .vstemplate:
<TemplateData>
<Name>MyProject A File</Name>
<Description>MyProject A File to do stuff</Description>
<Icon>A.ico</Icon>
<TemplateID>TemplateID_A</TemplateID>
<TemplateGroupID>MyTemplateGroupID</TemplateGroupID>
<ProjectType>CSharp</ProjectType>
<RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
<SortOrder>20</SortOrder>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
<DefaultName>Template_A.cs</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<ShowByDefault>false</ShowByDefault>
</TemplateData>
<TemplateContent>
<ProjectItem ReplaceParameters="true">Template_A.cs</ProjectItem>
</TemplateContent>
And on the package.cs:
// [ProvideProjectItem(typeof(MyProjectFactory), "MyTemplateGroupID",
// @"Templates\ProjectItems", 600)] // Took this out.
[ProvideProjectFactory(typeof(MyProjectFactory),
"My Project", "My Project Files (*.csproj);*.csproj",
null, null, @"Templates\Projects",
LanguageVsTemplate = "CSharp",
NewProjectRequireNewFolderVsTemplate = true,
TemplateGroupIDsVsTemplate="MyTemplateGroupID",
TemplateIDsVsTemplate = "TemplateID_A,TemplateID_B")]
public sealed class MyPackage : Package { ... }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是可能的,并且“框中”有一些项目模板可以执行此操作。例如,您会注意到,WPF 项目(页面、窗口、FlowDocument 等)的 C# 或 VB 项目模板仅在您使用 WPF 风格的项目时才会出现。
诀窍是在每个 vstemplate 文件中指定相同的 TemplateGroupID,并且然后在项目风味的注册中指定相同的 TemplateGroupID。
Yes this is possible and there are a few item templates "in the box" that do this. For example, you'll notice that the C# or VB item templates for WPF items (Page, Window, FlowDocument, etc...) only appear if you're working with a WPF-flavored project.
The trick is to specify the same TemplateGroupID in each vstemplate file, and then specify this same TemplateGroupID in the registration of your project flavor.