你是对的,我的第一个答案在浏览器中打开了页面,但没有启动网络服务器。试试下面的宏。它使用 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 方法中的路径即可。它是您在解决方案资源管理器中看到的文件的完整路径。此宏假定该文件是您的解决方案的一部分。