2009-07-29 193 views
131

如果在源文件评论中有一个URL,我可以“按CTRL +单击以关注链接”。但是,当我这样做时,链接将在Visual Studio中打开。我如何在我的网络浏览器中打开它 - 在我的情况下,Google Chrome?如何在Visual Studio中打开Web浏览器中的链接而不是Visual Studio中的链接?

+0

我正要说提交功能请求,但你猜怎么着。在VS2010beta1的编辑器视图中,自动链接实际上没有了。 – Bahbar 2009-11-27 17:06:19

+0

@Bahbar:在VS2010 RC中,链接已恢复。 – 2010-03-23 09:11:37

+5

2.5年后对此问题的任何更新?现在有更好的方法吗? – Borek 2011-12-13 19:54:32

回答

58

有提供这种行为称为Open in External Browser的延伸。它的工作原理在Visual Studio 2012年,2013年,2015年和2017年(旧版本available on GitHub支持Visual Studio 2010中)

由于去Dmitryhis answer指出这一点这个类似的问题。

编辑:Visual Studio团队终于开始上把这个权利到Visual Studio工作。 this功能请求的状态刚刚从“审阅中”移至“已启动”。

-4

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

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 

只要把你的光标在网址前和运行宏...

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 

使用方法:将光标放在URL之前的某处;运行宏(I映射为Ctrl移-G)