代码之家  ›  专栏  ›  技术社区  ›  WowtaH

Visual studio“在浏览器中查看”到特定页面的快捷方式?

  •  2
  • WowtaH  · 技术社区  · 16 年前

    我们正在使用 并想知道是否有办法为 在浏览器中查看 '-命令,但是 具有特定页面 从一个特定的(加载的)项目。

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

    有人知道这是否可能,如果可能,如何实现吗?

    谢谢 W

    2 回复  |  直到 16 年前
        1
  •  1
  •   Peter Macej    16 年前

    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方法中的路径。它是您在解决方案资源管理器中看到的文件的完整路径。此宏假定文件是解决方案的一部分。

        2
  •  0
  •   Peter Macej    16 年前

    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 button assign keyboard shortcut 去吧。