开发者

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

We are using Visual Studio 2008 and would like to kno开发者_如何学运维w 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜