ChatGPT解决这个技术问题 Extra ChatGPT

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

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?

Any updates on this question after 2.5 years? Is there a better way now?
Accepted answer doesn't work for Visual Studio 2012, so opened a new question stackoverflow.com/questions/13047914/…
Vote for this to be fixed in VS here.
Any update on this after 4 years?
Any update on this after 6 years? :)

m
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 GitHub supports Visual Studio 2010.)

Thanks goes to Dmitry for pointing this out in his answer to this similar question.

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


Thanks Mike! A nice, easy solution.
Thanks for the update Rob. It's a shame that we still need to use this in VS2015.
Works in VS2017 as well
For Anyone else wondering it will work for Visual Studio 2019, but I hope they just include it.
O
Owen Blacker

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...


I don't have VB installed but it looks like it'll work (if there is nothing at the end of the line past the URL), plus I hate having un-answered questions, so marking as answer. Thanks for your help :)
@Sam: You don't need VB installed to use Visual Studio macros. They just use the same syntax.
Is this something you have to install somehow?
Turns out Visual Studio 2012 doesn't support macros, that's why I couldn't install it. Try emacs.
O
Owen Blacker

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

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

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)


d
dylanh724

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

https://i.imgur.com/tmc6vBb.png


This doesn't appear to do anything for opening clickable links in files. Tried it, not sure what it does. Doesn't appear to do anything.
That has been there since at least VS2012, and nothing in the image you show there has anything to do with configuring a browser. From the docs: " Sets the editor used to open a Web page when you choose View Source on the page from the internal Web browser.". It's for viewing the source, not for preventing it from opening stuff in the internal browser in the first place.
c
christris

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

Windows-Support

or direct link to settings: ms-settings:defaultapps


b
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.


I thought of this too, but it does not apply to links directly in the source code, only to links in, say, the Help.
You're right only links in the internal navigator not in the source code pane.
-1 does not answer the question. :-)... If anyone has a solution that does not involve right click menu or CTRL click that would be even better :-)