我们是否对Microsoft Visual Studio有任何推荐的宏?

时间:2020-03-05 18:40:29  来源:igfitidea点击:

我们发现在Visual Studio中对代码操纵和自动化有用的一些宏是什么?

解决方案

回答

我们可能还希望添加代码段,它们有助于加快开发时间并提高生产率。

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

就宏而言,我通常不使用任何宏,但使用Visual Studio 2005的书中包含一些相当不错的宏。

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

回答

这是我在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), "¹") ' 1
        ReplaceAllChar(ChrW(178), "²") ' 2
        ReplaceAllChar(ChrW(179), "³") ' 3
        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

当我们必须进行任何类型的数据输入并想一次转义所有内容时,此功能很有用。

回答

这是我创建的,可让我们轻松地在解决方案中更改所有项目的目标框架版本:http://geekswithblogs.net/sdorman/archive/2008/07/18/visual-studio-2008-and-targetframeworkversion。 aspx

回答

我正在使用Jean-Paul Boodhoo的BDD宏。它在方法签名的标题行内用下划线替换空格字符。这样,我可以键入测试用例的名称,例如,作为普通句子,敲击键盘快捷键,并且我具有有效的方法签名。

回答

这是我的宏,用于关闭解决方案,删除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