Visual studio 'View in Browser' shortcut to specific page?

血红的双手。 提交于 2019-12-11 02:09:41

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2494417/visual-studio-view-in-browser-shortcut-to-specific-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!