创建不会出现在 Web 项目下的 VSTemplates(仅在无特色的项目下)
我们有一堆模板,其中一些仅在将新项目添加到 C# Web 应用程序项目时才可见(使用“Web”模板组 ID 进行过滤)。不过,我们的许多其他模板对于添加到 Web 项目没有意义(它们旨在添加到标准 C# 类库项目)。当我向 C# Web 应用程序项目添加新项目时,我想阻止显示这些模板。
我不确定这是否可行。我知道相反的情况也是可能的;创建仅显示在 Web 项目下的项目模板,但我希望我们的一些模板仅显示在无特色的 C# 项目上(而不 WebApp、WPF、工作流、 ETC)。
我查看了 HKCU\Software\Microsoft\VisualStudio\10.0Exp_Config\Projects{FAE04EC0-301F-11d3-BF4B-00C04F79EFBC} (原味的 C# 项目类型注册)下的注册表,可以看到它没有指定任何基于模板组 ID 进行过滤(看来这没有帮助)。有风味的项目子类型(例如工作流)似乎确实会过滤允许您添加的项目(例如,使用模板组 ID“WorkflowItemTemplateGroupID”),但无风味的项目似乎不会过滤其项目,因此不会过滤任何项目将 VisibleByDefault 设置为“false”的文件将始终不可见(因为它们无法指定模板组 ID)。
有办法做我想做的事吗?
We have a bunch of templates, some of which are only visible when adding a new item to a C# Web Application project (filtered using the "Web" template group ID). Many of our other templates, though, do not make sense to add to a web project (they are intended for adding to a standard C# class library project). I would like to prevent these templates from being displayed when I add a new item to a C# Web Application project.
I am not sure if this is possible to do. I know the inverse is possible; to create item templates that only show up under web projects, but I would like some of our templates to only show up on unflavored C# projects (not WebApp, WPF, Workflow, etc).
I took a look in the registry under HKCU\Software\Microsoft\VisualStudio\10.0Exp_Config\Projects{FAE04EC0-301F-11d3-BF4B-00C04F79EFBC} (the unflavoured C# project type registration), and I can see that it does not specify any filtering based on template group ID (so that's no help, it seems). Flavoured project subtypes, such as Workflow do seem to filter the items they allow you to add (using, for example, a template group ID of "WorkflowItemTemplateGroupID"), but it seems like unflavoured projects don't filter their items and therefore any items that have VisibleByDefault set to "false" will always be invisible (since they can't specify a template group ID).
Is there a way to do what I'm trying to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了如何使用 SVsRegisterNewDialogFilters 服务来执行此操作 (这是拼图中缺失的一块)。
它使您能够提供 IVsFilterAddProjectItemDlg 实现,每当调用 add-project-item 对话框时都会调用该实现(无论是谁调用它)。对于 Web/Silverlight 项目,它使用与普通 C# 项目不同的项目类型 GUID 进行调用(因此我可以简单地过滤掉我们的各种模板目录)。
I figured out how to do this using the SVsRegisterNewDialogFilters service (which was the missing piece of the puzzle).
It enables you to supply an implementation of IVsFilterAddProjectItemDlg implementation which is called whenever the add-project-item dialog is invoked (regardless who invokes it). It is called with a different project type GUID for Web / Silverlight projects than for unflavoured C# projects (so I can simply filter out our various template directories .