J'ai une macro qui ajoute l'en-tête de copyright à mes fichiers VB, mais malheureusement, il ne se comporte pas comme prévu.Besoin d'aide avec Visual Studio Macro
Voici le 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
Mais le problème est qu'il est l'ajout de quatre guillemets à la fin de l'insert que je dois aller un supprimer manuellement. D'où viennent ces guillemets?
' --------------------------------
' <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>
' ---------------------------------
""""
Cependant, si j'utilise des guillemets simples, tout va bien.
sb.Append("' <copyright file='" & docName & "' company='" & companyName & "'>")
Si je fais un pas en arrière à travers "Annuler" dans le fichier, ils commencent à "construire" que les citations sont écrites sur '' –
ainsi tous les une citation est écrite dans le fichier, une seconde est également écrite. –
Une sorte de style Resharper de l'outil qui ajoute automatiquement la seconde "lorsque vous tapez le premier? –