代码之家  ›  专栏  ›  技术社区  ›  xofz

如何在Web浏览器中而不是在Visual Studio中打开链接?

  •  133
  • xofz  · 技术社区  · 17 年前

    如果源文件注释中有一个URL,我可以“ctrl+单击以跟踪链接”。但是,当我执行此操作时,链接将在Visual Studio中打开。我怎样才能让它在我的网络浏览器中打开——在我的例子中,谷歌浏览器?

    4 回复  |  直到 9 年前
        1
  •  61
  •   mikesigs    9 年前

    提供此行为的扩展名为 Open in External Browser . 它在Visual Studio 2012、2013、2015和2017中工作。(旧版本) available on GitHub 支持Visual Studio 2010。)

    谢谢 Dmitry 因为在里面指出了这一点 his answer 关于这个类似的问题。

    编辑:Visual Studio团队终于开始将此项功能应用到Visual Studio中。现状 this 功能请求刚从“正在审阅”移到“已启动”。

        2
  •  7
  •   Owen Blacker Aditya    12 年前

    我找不到这个的设置,所以我写了一个简单的宏,你可以使用。可以将其绑定到键组合,如所有宏。在我们得到更好的答案之前,这项工作将完成。

    Sub OpenURLInChrome()
       'copy to end of line
       DTE.ActiveDocument.Selection.EndOfLine(True)
    
      'set var
       Dim url As String = DTE.ActiveDocument.Selection.Text
    
       'launch chrome with url
       System.Diagnostics.Process.Start( _
          Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) _
          + "\Google\Chrome\Application\chrome.exe", url)
    End Sub
    

    只需将光标放在URL前面并运行宏…

        3
  •  5
  •   Owen Blacker Aditya    12 年前

    这是对mracoker上面建议的宏的改进。

    此宏在当前行中查找URL,并且不会像前一个答案那样捕获URL后面的文本。

    Sub OpenURLInChrome()
    
       ' Select to end of line
       DTE.ActiveDocument.Selection.EndOfLine(True)
       Dim selection As TextSelection = DTE.ActiveDocument.Selection
    
       ' Find URL within selection
       Dim match = System.Text.RegularExpressions.Regex.Match( _
          selection.Text, ".*(http\S+)")
    
       Dim url As String = ""
       If (match.Success) Then
          If match.Groups.Count = 2 Then
             url = match.Groups(1).Value
          End If
       End If
    
       ' Remove selection
       selection.SwapAnchor()
       selection.Collapse()
    
       If (url = String.Empty) Then
           MsgBox("No URL found")
       End If
    
       ' Launch chrome with url
       System.Diagnostics.Process.Start( _
          Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) _
          + "\Google\Chrome\Application\chrome.exe", url)
    End Sub
    

    要使用:将光标放在URL之前的某个位置;运行宏(我映射到ctrl-shift-g)

        4
  •  -4
  •   backslash17    17 年前

    在VS2008中,只需右键单击链接并选择“在外部窗口中打开链接”。您必须选择chrome作为默认浏览器。