2

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

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

任何人都知道这是否可能,如果可以,如何实现?

谢谢!W。

4

2 回答 2

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

于 2010-03-23T12:50:58.793 回答
0

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

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

创建宏并修改 url 变量。然后,您可以创建工具栏或菜单按钮为其分配键盘快捷键

于 2010-03-23T08:07:29.167 回答