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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1201570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:49:09  来源:igfitidea点击:

How do I open links in Visual Studio in my web browser and not in Visual Studio?

visual-studiohyperlink

提问by xofz

If there is a URL in a source file comment, I can "CTRL + click to follow link." However, when I do this, the link opens inside Visual Studio. How can I make it open in my web browser--in my case, Google Chrome?

如果源文件注释中有 URL,我可以“CTRL + 单击以关注链接”。但是,当我这样做时,链接会在 Visual Studio 中打开。我怎样才能让它在我的网络浏览器中打开——在我的例子中是谷歌浏览器?

采纳答案by mikesigs

There is an extension that provides this behavior called Open in External Browser. It works in Visual Studio 2012, 2013, 2015 and 2017. (An old version available on GitHubsupports Visual Studio 2010.)

有一个扩展提供了这种行为,称为Open in External Browser。它适用于 Visual Studio 2012、2013、2015 和 2017。(GitHub 上提供的旧版本支持 Visual Studio 2010。)

Thanks goes to Dmitryfor pointing this out in his answerto this similar question.

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

EDIT: The Visual Studio team is finally starting to work on putting this right into Visual Studio. Status of thisfeature request just moved from "Under Review" to "Started".

编辑:Visual Studio 团队终于开始着手将其放入 Visual Studio。功能请求的状态刚刚从“审核中”移至“已开始”。

回答by mracoker

I could not find a setting for this so I wrote a simple macro that you can use. You can bind this to a key-combo like all macros. This will get the job done until we get a better answer.

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

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

Just put your cursor in front of the url and run the macro...

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

回答by Terrence

This is an improvement on the macro suggested above by mracoker.

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

This macro looks for a URL on the current line and does not capture text after the URL as the previous answer did.

此宏在当前行中查找 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

To use: place cursor somewhere before the URL; Run Macro (I mapped to Ctrl-Shift-G)

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

回答by dylanh724

2019 Update:All the answers are old. There's now a native way to do this in options in VS2019 Community:

2019 更新:所有答案都是旧的。现在在 VS2019 社区的选项中有一种本地方法可以做到这一点:

Options >>Web Browser

选项 >>网络浏览器

回答by christris

This works for me. I changed the default browser in Windows.

这对我有用。我更改了 Windows 中的默认浏览器。

Windows-Support

Windows-支持

or direct link to settings: ms-settings:defaultapps

或直接链接到设置:ms-settings:defaultapps

回答by backslash17

In VS2008 , just right click on the link and select "Open link in external window". You have to select Chrome as your default browser.

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