VS 2010 SDK. Templates

*爱你&永不变心* 提交于 2019-12-10 20:27:37

问题


If you try and create an MVC3 project, you’ll see that you have an ability to add Controller or View with rc. And context menu you get on Controller folder with rc will magically suggest to add Controller while on the Views you’ll be suggested to add View.

As I understand, to achieve this I need to bind somehow 4 things. Project template, Item template, T4 templates (used to generate Contoller class or View) and a wizard lieing between T4 and Intem template (within WizardExtension section in Item Template).

How to have all these goods MVC3 project has for a custom template? I couldn’t dig how to bind those 4 things. Maybe somewhere in msdn there is an article I missed (I looked at “Visual Studio Templates” but that did not help much in understanding how to get to my goal). Or maybe someone had a nice experience doing something similar.

P.s. I’m using VS 2010 SDK SP1 Experimental Instance


回答1:


The functionality you see in MVC 3 projects is implemented as follows:

MVC 3 projects are specially marked using an MVC 3 project type GUID (you can see it in a project's csproj file). The presence of this GUID triggers Visual Studio to load the MVC Tools VSPackage. The VSPackage is responsible for adding commands and other UI elements (e.g. the Add View button) that become active depending on what you select in your project. These commands invoke dialogs to gather user input which is then used to instantiate a T4 template host and invoke the template.

The VS item templates and template wizards only come into play when you try to add a view using the Add New Item dialog.

Overall creating a VSPackage is a pretty complicated subject. A good place to get started is here: http://msdn.microsoft.com/en-us/vstudio/ff677564.



来源:https://stackoverflow.com/questions/7099848/vs-2010-sdk-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!