【问题标题】:Visual studio 'View in Browser' shortcut to specific page?Visual Studio“在浏览器中查看”特定页面的快捷方式?
【发布时间】:2010-03-22 17:36:01
【问题描述】:

我们正在使用 Visual Studio 2008,想知道是否可以为“在浏览器中查看”创建(键盘或工具栏)快捷方式-命令,但带有来自特定(已加载)项目的特定页面

我们总是从“Project-x”的“Somepage.aspx”开始测试/调试我们的应用程序。我想从这个特定的项目创建一个使用这个特定页面/文件的“在浏览器中查看”的快捷方式。所以即使我目前正在处理另一个项目中的另一个文件(来自同一个解决方案)它应该仍然可以工作......

有人知道这是否可行,如果可以,如何实现?

谢谢!

【问题讨论】:

    标签: visual-studio shortcut


    【解决方案1】:

    你是对的,我的第一个答案在浏览器中打开了页面,但没有启动网络服务器。试试下面的宏。它使用 ViewinBrowser 命令,因此它应该可以按预期工作。

    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    
    

    只需更改 GetItem 方法中的路径。它是您在解决方案资源管理器中看到的文件的完整路径。此宏假定文件是您的解决方案的一部分。

    【讨论】:

    • 嗨彼得..再次感谢..这比第一个效果更好,但是(:))它仅在焦点已经在解决方案资源管理器中时才有效,当焦点时它不起作用在代码编辑器中。对此有何建议?
    • 只需在宏开头添加以下内容: Dim oldActiveWindow As EnvDTE.Window = DTE.ActiveWindow DTE.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate() 并在末尾添加以下内容: oldActiveWindow.Activate()
    • 像魅力一样工作......谢谢!
    【解决方案2】:

    以下宏在您的默认浏览器中打开特定页面:

    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 并修改 url 变量。然后你可以create a toolbar or menu buttonassign keyboard shortcut 给它。

    【讨论】:

    • 嗨,彼得...看起来很有希望。它可以工作,但是,在打开浏览器以显示页面之前,它不会像 Visual Studio 上下文菜单“在浏览器中查看”那样启动我的开发网络服务器。对此有什么建议吗?谢谢!
    猜你喜欢
    • 2014-01-23
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多