您发现在Visual Studio中用于代码操作和自动化的一些宏有哪些?
这是我关闭解决方案的宏,删除intellisense文件,然后重新打开解决方案.如果您使用的是原生C++,则必不可少.
Sub UpdateIntellisense() Dim solution As Solution = DTE.Solution Dim filename As String = solution.FullName Dim ncbFile As System.Text.StringBuilder = New System.Text.StringBuilder ncbFile.Append(System.IO.Path.GetDirectoryName(filename) + "\") ncbFile.Append(System.IO.Path.GetFileNameWithoutExtension(filename)) ncbFile.Append(".ncb") solution.Close(True) System.IO.File.Delete(ncbFile.ToString()) solution.Open(filename) End Sub
这是我在HTML和XML文件上使用的方便之一:
''''replaceunicodechars.vb Option Strict Off Option Explicit Off Imports EnvDTE Imports System.Diagnostics Public Module ReplaceUnicodeChars Sub ReplaceUnicodeChars() DTE.ExecuteCommand("Edit.Find") ReplaceAllChar(ChrW(8230), "…") ' ellipses ReplaceAllChar(ChrW(8220), "“") ' left double quote ReplaceAllChar(ChrW(8221), "”") ' right double quote ReplaceAllChar(ChrW(8216), "‘") ' left single quote ReplaceAllChar(ChrW(8217), "’") ' right single quote ReplaceAllChar(ChrW(8211), "–") ' en dash ReplaceAllChar(ChrW(8212), "—") ' em dash ReplaceAllChar(ChrW(176), "°") ' ° ReplaceAllChar(ChrW(188), "¼") ' ¼ ReplaceAllChar(ChrW(189), "½") ' ½ ReplaceAllChar(ChrW(169), "©") ' © ReplaceAllChar(ChrW(174), "®") ' ® ReplaceAllChar(ChrW(8224), "†") ' dagger ReplaceAllChar(ChrW(8225), "‡") ' double-dagger ReplaceAllChar(ChrW(185), "¹") ' ¹ ReplaceAllChar(ChrW(178), "²") ' ² ReplaceAllChar(ChrW(179), "³") ' ³ ReplaceAllChar(ChrW(153), "™") ' ™ ''ReplaceAllChar(ChrW(0), "") DTE.Windows.Item(Constants.vsWindowKindFindReplace).Close() End Sub Sub ReplaceAllChar(ByVal findWhat, ByVal replaceWith) DTE.Find.FindWhat = findWhat DTE.Find.ReplaceWith = replaceWith DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument DTE.Find.MatchCase = False DTE.Find.MatchWholeWord = False DTE.Find.MatchInHiddenText = True DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone DTE.Find.Action = vsFindAction.vsFindActionReplaceAll DTE.Find.Execute() End Sub End Module
当您必须执行任何类型的数据输入并希望一次性转义所有内容时,它非常有用.