views:

13

answers:

1

I've got a macro that adds the copyright header to my VB files, but unfortunately it's not behaving as expected.

Here's the Macro

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

Public Module CopyrightCode
    Sub AddCopyrightHeader()

        Dim doc As Document
        Dim docName As String
        Dim companyName As String = "My Company"
        Dim authorName As String = "rockinthesixstring"
        Dim authorEmail As String = "[email protected]"
        Dim copyrightText As String = "All code is Copyright © " & vbCrLf & _
        "'      -   My Exceptional Company (http://example.com)" & vbCrLf & _
        "'     All Rights Reserved"

        ' 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()

        Dim sb As New StringBuilder
        sb.Append("' --------------------------------")
        sb.Append(vbCrLf)
        sb.Append("' <copyright file=""" & docName & """ company=""" & companyName & """>")
        sb.Append(vbCrLf)
        sb.Append(copyrightText)
        sb.Append(vbCrLf)
        sb.Append("' </copyright>")
        sb.Append(vbCrLf)
        sb.Append("' <author>" & authorName & "</author>")
        sb.Append(vbCrLf)
        sb.Append("' <email>" & authorEmail & "</email>")
        sb.Append(vbCrLf)
        sb.Append("' <date>" & FormatDateTime(Date.Now, vbLongDate) & "</date>")
        sb.Append(vbCrLf)
        sb.Append("' ---------------------------------")

        ' Write first line
        DTE.ActiveDocument.Selection.LineUp()
        DTE.ActiveDocument.Selection.Text = sb.ToString

    End Sub
End Module

But the problem is that it's adding FOUR quotation marks at the end of the insert that I have to go an manually remove. Where are these quotation marks coming from?

' --------------------------------  
' <copyright file="MyFile.vb" company="My Company">  
'     All code is Copyright ©     
'      -   My Exceptional Company (http://example.com) 
'     All Rights Reserved  
' </copyright>  
' <author>rockinthesixstring</author>  
' <email>[email protected]</email>  
' <date>Monday, July 05, 2010</date>  
' ---------------------------------   
""""  

However If I use single quotes, it's all good.

    sb.Append("' <copyright file='" & docName & "' company='" & companyName & "'>")
+2  A: 

No repro, they don't come from the macro. Consider some kind of Visual Studio add-on as the source of the problem.

Hans Passant
If I step backwards through "Undo" in the file, they start to "build" as the quotes are getting written out on `<copyright file="MyFile.vb" company="My Company">`
rockinthesixstring
so every time a quotation is written to the file, a second is written as well.
rockinthesixstring
Some kind of Resharper style of tool that automatically adds the second " when you type the first one?
Hans Passant
ah, that's exactly it... Resharper. Dang. Ok, I'll stick with single quotes on this one.
rockinthesixstring