2010-07-05 98 views
0

我有一個宏,它將版權標題添加到我的VB文件中,但不幸的是它的行爲並不像預期的那樣。Visual Studio宏需要幫助

這裏的宏

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 

但問題是,它增加四個引號的,我必須去一個手動刪除插件末端。這些引號來自哪裏?

' -------------------------------- 
' <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> 
' --------------------------------- 
"""" 

但是如果我使用單引號,這一切都很好。

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

回答

2

沒有repro,它們不是來自宏。考慮某種Visual Studio插件作爲問題的根源。

+0

如果我通過文件中的「撤銷」向後退一步,他們開始「建立」,因爲引用已經寫在'「 – 2010-07-05 18:52:19

+0

」時間將一個報價寫入文件,另一個也寫入。 – 2010-07-05 18:52:47

+0

某種Resharper風格的工具,會自動添加第二個「當你鍵入第一個? – 2010-07-05 18:57:37