How to store reusable code in Visual Studio 2010?

陌路散爱 提交于 2019-12-22 08:36:48

问题


Is there any way I could save my block of code in Visual Studio 2010 and reuse it in my future web applications without having to "Add existing files"? Is there a feature in VS2010 that lets you globally store these blocks of code?

Thanks!


回答1:


Oded pretty much covered it but I'll just reiterate here. There are three main ways you can do this depending on how much code you want to store.

For a little code just copy the code to your Toolbox: http://blogs.msdn.com/b/zainnab/archive/2010/01/24/drag-and-drop-code-onto-the-toolbox-vstiptool0007.aspx

For a little code to very large blocks of code (with some intelligence for putting in values) you can use code snippets: http://blogs.msdn.com/b/zainnab/archive/tags/tips+and+tricks/snippet/

And for lots of custom files, resources, etc... that essentially make up a new project you should use project templates: http://blogs.msdn.com/b/zainnab/archive/2010/02/22/roll-your-own-project-or-item-with-the-export-template-wizard-vstipproj0004.aspx




回答2:


Visual Studio has a feature called code snippets, which will allow you to do exactly that.

If you want a more advanced use - for whole files, sets of files and even whole projects, use templates.



来源:https://stackoverflow.com/questions/3177473/how-to-store-reusable-code-in-visual-studio-2010

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