开发者

Custom Visual Studio Context Menus

I want to use T4 templates to automatically create some code but I want to add a user input box (to ask for a name, for example) similar to the MVC3 "Add View" / "Add Controller" dialog when you right click on a specific folder. Is this poss开发者_JAVA百科ible with pure T4 templates or is it going to result in a writing a VS plugin DLL? If it involves writing a DLL can I just plop that into the projects reference and use it per-project or does it have to be registered individually on each machine?


Managed to figure it out. I probably should of tried this first. Just add the required imports to your T4 template:

<#@ assembly name="System.Windows.Forms.dll" #>
<#@ assembly name="System.Drawing.dll" #>
<#@ import namespace="System.Windows.Forms" #>
<#@ import namespace="System.Drawing" #>

and then create a form programmatically with a label, input box and button. On DialogResult.OK (for example) just read the input value and do what you need with it. Works perfectly :-)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜