Visual studio 'View in Browser' shortcut t

2019-07-19 04:22发布

We are using Visual Studio 2008 and would like to know if there is a way to create a (keyboard or toolbar) shortcut for the 'View in Browser'-command, but with a specific page from a specific (loaded) project.

We always start testing/debugging our app from "Somepage.aspx" from "Project-x". I would like to make a shortcut that does 'View in Browser' with this specific page/file, from this specific project. So even if I am currently working on another file in another project (from the same solution) it should still work...

Anybody know if this is possible, and if so, how this can be achieved?

Thanks! W.

2条回答
Lonely孤独者°
2楼-- · 2019-07-19 04:37

You are right, my first answer opens the page in browser but doesn't launch webserver. Try the following macro. It uses ViewinBrowser command so it should work as expected.

Sub OpenMyPage()
    Dim solutionExplorerHier As EnvDTE.UIHierarchy
    solutionExplorerHier = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object
    Dim oldSelected As Object = solutionExplorerHier.SelectedItems
    solutionExplorerHier.GetItem("MySolution\MyProject\HTMLPage1.htm").Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.ExecuteCommand("File.ViewinBrowser")

    'restore selected items
    Dim item As EnvDTE.UIHierarchyItem
    For Each item In DirectCast(oldSelected, Array)
        item.Select(vsUISelectionType.vsUISelectionTypeSelect)
    Next
End Sub    

Just change the path in GetItem method. It is the complete path to the file you see in your Solution explorer. This macro assumes that the file is a part of your solution.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-07-19 04:41

The following macro opens specific page in your default browser:

Sub OpenMyPage()
    Try
        Dim url As String
        url = "C:\HTMLPage1.htm"
        'enclose URL in double quotes
        url = """" & url & """"
        DTE.ExecuteCommand("nav", url & " /new /ext")
        'nav is alias for View.ShowWebBrowser command
        'Syntax:
        'View.ShowWebBrowser URL [/new][/ext]
        '
        '/new 
        ' Optional. Specifies that the page appears in a new instance of the Web browser.
        '/ext 
        ' Optional. Specifies that the page appears in the default Web browser outside of the IDE.
    Catch ex As Exception
    End Try
End Sub

Create the macro and modify the url variable. Then you can create a toolbar or menu button or assign keyboard shortcut to it.

查看更多
登录 后发表回答