您是否为Microsoft Visual Studio推荐了任何宏?

rjz*_*zii 8 macros automation visual-studio

您发现在Visual Studio中用于代码操作和自动化的一些宏有哪些?

Joh*_*son 9

这是我关闭解决方案的宏,删除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
Run Code Online (Sandbox Code Playgroud)


tra*_*vis 5

这是我在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
Run Code Online (Sandbox Code Playgroud)

当您必须执行任何类型的数据输入并希望一次性转义所有内容时,它非常有用.


小智 0

您可能还想添加代码片段,它们有助于加快开发时间并提高生产力。

默认安装附带标准 VB 代码片段。C# 代码片段必须单独下载和添加。(下面的链接)

就宏而言,我通常没有使用过任何宏,但是《working with Visual studio 2005》一书中有一些非常好的宏。

C# 代码片段链接: http://www.codinghorror.com/blog/files/ms-csharp-snippets.7z.zip (Jeff Atwood 提供了链接)HIH