开发者

Creating VSTemplates that DO NOT appear under web projects (only under unflavoured projects)

开发者 https://www.devze.com 2023-04-02 18:32 出处:网络
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,

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 templ开发者_如何学Cates 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?


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 .

0

精彩评论

暂无评论...
验证码 换一张
取 消