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

xof*_*ofz 134 hyperlink visual-studio

如果源文件注释中有URL,我可以"按住CTRL并单击以关注链接".但是,当我这样做时,链接在Visual Studio中打开.如何在我的网络浏览器中打开它 - 在我的情况下,谷歌浏览器?

mik*_*igs 63

有一个扩展提供了这种在外部浏览器中称为Open的行为.它适用于Visual Studio 2012,2013,2015和2017.(GitHub上提供的旧版本支持Visual Studio 2010.)

感谢Dmitry对这个类似问题的回答中指出这一点.

编辑:Visual Studio团队终于开始将这个权利放入Visual Studio.功能请求的状态刚刚从"正在审核"移至"已启动".

  • 感谢Rob的更新.令人遗憾的是,我们仍然需要在VS2015中使用它. (10认同)
  • 就像一个FYI,这也适用于VS2015 (2认同)

小智 7

我找不到这个设置所以我写了一个你可以使用的简单宏.您可以将其绑定到像所有宏一样的键组合.这将完成工作,直到我们得到更好的答案.

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
Run Code Online (Sandbox Code Playgroud)

只需将光标放在网址前面并运行宏...

  • 原来Visual Studio 2012不支持宏,这就是我无法安装它的原因.试试emacs. (3认同)
  • @Sam:您不需要安装VB即可使用Visual Studio宏.他们只使用相同的语法. (2认同)

Ter*_*nce 5

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

使用:将光标放在URL之前的某处; 运行宏(我映射到Ctrl-Shift-G)