Adding the Macro:
1. Click “Tools” menu
2. Click “Macros” menu item
3. Click “Macros IDE…” menu choice
4. Right click on “My Macros”
5. Click “Add” menu item
6. Choose “Add Module…” (a module is a VB term for a static C# class with all static members)
7. Enter the name of “FileHeader” (or whatever you want to name your module)
8. Paste the code below and update any variables to match your organization or name
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module FileHeader
Sub FileHeader()
Dim doc As Document
Dim docName As String
Dim companyName As String = "My Company"
Dim authorName As String = "Benedict Alphonse"
Dim copyrightText As String = "© 2009 My Company. All rights reserved"
Dim Email As String = "benedictkmu@gmail.com"
Dim Summary As String
' Get the name of this object from the file name
doc = DTE.ActiveDocument
' Get the name of the current document
docName = doc.Name
' Set selection to top of document
DTE.ActiveDocument.Selection.StartOfDocument()
DTE.ActiveDocument.Selection.NewLine()
' Write first line
DTE.ActiveDocument.Selection.LineUp()
DTE.ActiveDocument.Selection.Text = "#region File Header"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "// ******************************************************************************************************************"
DTE.ActiveDocument.Selection.NewLine()
' Write copyright tag
DTE.ActiveDocument.Selection.Text = "// "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "// " + copyrightText
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "// "
' Write author name tag (optional)
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "// " + authorName + " "
DTE.ActiveDocument.Selection.NewLine()
' Write email tag (optional)
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "// " + Email + " "
DTE.ActiveDocument.Selection.NewLine()
' Write email tag (optional)
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "// " + docName + " "
DTE.ActiveDocument.Selection.NewLine()
' Write email tag (optional)
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//------------------------------Revision History---------------------------------------------------------------------"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "// Date Author Change Log Comments"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//" + DateTime.Now.ToString("MMM/dd/yyyy") + " " + authorName + " " + "Newly Created" + " "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "// "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "// "
DTE.ActiveDocument.Selection.NewLine()
' Write last line
DTE.ActiveDocument.Selection.Text = "// ******************************************************************************************************************"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "#endregion"
End Sub
End Module
Macro Results
This creates the following text inserted into the top of the source code document:
#region File Header // ****************************************************************************************************************** //Adding Macro to Toolbar: To add this to a toolbar in your IDE:// © 2009 My Company. All rights reserved // //Benedict Alphonse //benedictkmu@gmail.com //ReportUtils.cs //------------------------------Revision History--------------------------------------------------------------------- // Date Author Change Log Comments //Dec/01/2009 Benedict Alphonse Newly Created // // // ****************************************************************************************************************** #endregion
1. Click “Tools” menu
2. Click “Customize…” menu choice
3. Activate “Commands” tab
4. Choose “Macros” category
5. Select “MyMacros.FileHeader.FileHeader” (or whatever you named it)
6. Drag command to your toolbar.
7. You can customize the icon, text, visibility of text/icon, etc. by right clicking on the toolbar button
8. Close customization dialog


0 Responses to "ADD FILE HEADER OR CHANGE LOG TO FILES IN VISUAL STUDIO BY USING MACRO"
Post a Comment