56 subscribers








  |  Technology  |  Science Stuff  |  Travel  |  Golf  |  Entertainment  |  Buddhism  |  Finance and Investing  |  Austin  |  India  |  Diet, Health  |  Petitions, Causes  |  

Posted on by Anuj Varma
Inserting copyright notice into your source files

I found a simple macro to help with this task. From Visual Studio, navigate to Tools—>Macros—>New Macro Project (This launches a new IDE)  – and copy and paste the code below.  When you ‘run (Debug)’ this macro, it will insert the copyright notice into the currently open source file. You do have to run this for each source file. If you want a short(er) cut, simply define a context menu shortcut to this macro – as described in this post.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module AddCopyrightHeader

    Sub FileHeader()

        Dim doc As Document
        Dim docName As String
        Dim companyName As String = "ANUJ Technologies Inc."
        Dim authorName As String = "Anuj Varma, www.anujvarma.com"
        Dim copyrightText As String = "Copyright (c) " + DateString.ToString() + " All Right Reserved"
        Dim summaryText As String = "Class representing a {0} entity."

        ' 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()
        DTE.ActiveDocument.Selection.LineUp()

        ' Write copyright tag
        DTE.ActiveDocument.Selection.Text = "// <copyright file=""" + docName + """ company=""" + companyName + """>"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "// " + copyrightText
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "// </copyright>"

        ' Write author name tag (optional)
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "// <author>" + authorName + "</author>"

        ' Write date tag (optional)
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "// <date>" + DateString.ToString() + "</date>"

        ' Write summary tag (optional)
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "// <summary>" + String.Format(summaryText, docName) + "</summary>"
        DTE.ActiveDocument.Selection.NewLine()

    End Sub

End Module
Recent Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

*