Enable Visual Studio to automatically add header comments

Source: Internet
Author: User
In the daily development process, we often need to add comments, copyrights, and other information to our class files. In the past, we copied and pasted the information text. If we added one or two pieces of information, it is very troublesome to add a lot. Is there a good solution to reduce this repetitive work? The answer is yes. In fact, each file we add is automatically generated according to the class library template, so you only need to modify the class library template of Visual Studio.

First, find the \ common7 \ ide \ itemtemplatescache \ CSHARP \ directory under the installation path of Visual Studio (2005, 2008, 2010). There are many directories on it, windows forms is the template directory for developing Windows Forms programs, and Web is the template directory for web project files. Go to the web directory and select "2052" ("2052" is the Chinese directory. Many directories with .zip are displayed. For example, to modify the template on the web page, modify "\ webform.zip \ default. aspx. cs" and open "default. aspx. cs.

  1. Using system;
  2. Using system. Collections. Generic;
  3. $ If $ ($ targetframeworkversion $ == 3.5) using system. LINQ;
  4. $ Endif $ using system. Web;
  5. Using system. Web. UI;
  6. Using system. Web. UI. webcontrols;
  7. Namespace $ rootnamespace $
  8. {
  9. Public partial class $ classname $: system. Web. UI. Page
  10. {
  11. Protected void page_load (Object sender, eventargs E)
  12. {
  13. }
  14. }
  15. }

The characters between the "$" symbols in the Code are template variables. For more information about the variables, see:

  1. <Strong> time $ date
  2. $ Year
  3. $ Clrversion $ CLR version
  4. $ Guid $ The GUID used to replace the project guid in the project file. You can specify up to 10 unique guid1 guids )).
  5. $ Itemname $ name provided by the user in the dialog box.
  6. $ Machinename $ name of the current computer (for example, computer01 ).
  7. $ Projectname $ name provided by the user in the dialog box.
  8. $ Registeredorganization $ registry key value in HKLM \ Software \ Microsoft \ Windows NT \ CurrentVersion \ registeredorganization.
  9. $ Rootnamespace $ root namespace of the current project. This parameter is used to replace the namespace in the items added to the forward project.
  10. $ Safeitemname $ name provided by the user in the "Add new item" dialog box, excluding all unsafe characters and spaces.
  11. $ Safeprojectname $ name provided by the user in the "New Project" dialog box, excluding all unsafe characters and spaces.
  12. $ Time $ the current time in the format of DD/MM/YYYY 00:00:00.
  13. $ Userdomain $ current user domain.
  14. $ Username $ current user name.
  15. </Strong>

My annotation example:

  1. /*************************************** *********************************
  2. * Project name: work log system
  3. * Project description:
  4. * Class Name: userinfo
  5. * Version number: v1.0.0.0
  6. * Description: User Information Management
  7. * Author: lingyu drifting
  8. * Creation Time: 13:19:28
  9. * Updated at: 13:19:28
  10. **************************************** ********************************
  11. * Copyright @ Ling Yu studio 2011. All rights reserved.
  12. **************************************** ********************************/

Follow the above instance design template:

  1. /*************************************** *********************************
  2. * Project name: $ rootnamespace $
  3. * Project description:
  4. * Class Name: $ safeitemrootname $
  5. * Version number: v1.0.0.0
  6. * Description:
  7. * OPERATOR: $ username $
  8. * Creation Time: $ time $
  9. * Update Time: $ time $
  10. **************************************** ********************************
  11. * Copyright @ Ling Yu studio $ year $. All rights reserved.
  12. **************************************** ********************************/
  1. <PRE class = "CSHARP" name = "code"> using system;
  2. Using system. Collections. Generic;
  3. $ If $ ($ targetframeworkversion $ == 3.5) using system. LINQ;
  4. $ Endif $ using system. Web;
  5. Using system. Web. UI;
  6. Using system. Web. UI. webcontrols;
  7. Namespace $ rootnamespace $
  8. {
  9. Public partial class $ classname $: system. Web. UI. Page
  10. {
  11. Protected void page_load (Object sender, eventargs E)
  12. {
  13. }
  14. }
  15. }
  16. </PRE>
  17. <PRE> </PRE>
  18. <P> <br>
  19. Generated file: <br>
  20. </P>
  21. <PRE class = "CSHARP" name = "code"> /************************** **************************************** ******
  22. * Project name: work log system
  23. * Project description:
  24. * Class Name: default2
  25. * Version number: v1.0.0.0
  26. * Description:
  27. * Author: lingyu drifting
  28. * Creation Time: 14:26:49
  29. * Updated on: 14:26:49
  30. **************************************** ********************************
  31. * Copyright @ Ling Yu studio 2012. All rights reserved.
  32. **************************************** ********************************/
  33. Using system;
  34. Using system. Collections. Generic;
  35. Using system. LINQ;
  36. Using system. Web;
  37. Using system. Web. UI;
  38. Using system. Web. UI. webcontrols;
  39. Public partial class default2: system. Web. UI. Page
  40. {
  41. Protected void page_load (Object sender, eventargs E)
  42. {
  43. }
  44. }
  45. </PRE>
  46. <P> </P>
  47. <P> modify other templates as described above. </P>
  48. <P> <br>
  49. </P>

Enable Visual Studio to automatically add header comments

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.