我不是在请求自动关注解决方案资源管理器中当前文件的选项。这个问题已经在这个问题中得到了回答,并且我已经关闭了此选项,因为我讨厌这种行为。
我想要一个快捷方式(或宏、或……)跳转到我当前正在编辑的文件在解决方案资源管理器中的位置。
我不是在请求自动关注解决方案资源管理器中当前文件的选项。这个问题已经在这个问题中得到了回答,并且我已经关闭了此选项,因为我讨厌这种行为。
我想要一个快捷方式(或宏、或……)跳转到我当前正在编辑的文件在解决方案资源管理器中的位置。
在VS 2013中有一个内置的键盘快捷方式 (CTRL+\, S)
或点击下图中突出显示的按钮。
如果您不喜欢默认组合,还可以自定义键盘快捷方式 :)
在使用Visual Studio 2015和ReSharper时,我可以按下Shift + Alt + L来在“解决方案资源管理器”中高亮显示当前正在编辑的文件。
要在“解决方案资源管理器”中找到您当前正在编辑的文件:
Ctrl + W + S
我曾经使用 Shift + Alt + L
,但由于某种原因它现在不再起作用。
其他建议(Ctrl+\,S
和 Ctrl+[,S
和 Ctrl + ` + S)在VS2015中对我无效。我不使用resharper,并且不喜欢在简单的快捷方式可用时使用宏。
对于VS2010,我找到了这个宏,并且适用于我:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Public Module Utilities
Public Sub TrackProjectItem()
Dim solution As Solution2 = DTE.Solution
If Not solution.IsOpen OrElse DTE.ActiveDocument Is Nothing Then Return
solution.FindProjectItem(DTE.ActiveDocument.FullName).ExpandView()
Dim FileName As String = DTE.ActiveDocument.FullName
Dim SolutionExplorerPath As String
Dim items As EnvDTE.UIHierarchyItems = DTE.ToolWindows.SolutionExplorer.UIHierarchyItems
Dim item As Object = FindItem(items, FileName, SolutionExplorerPath)
If item Is Nothing Then
MsgBox("Couldn't find the item in Solution Explorer.")
Return
End If
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
DTE.ActiveWindow.Object.GetItem(SolutionExplorerPath).Select(vsUISelectionType.vsUISelectionTypeSelect)
End Sub
Public Function FindItem(ByVal Children As UIHierarchyItems, ByVal FileName As String, ByRef SolutionExplorerPath As String) As Object
For Each CurrentItem As UIHierarchyItem In Children
Dim TypeName As String = Microsoft.VisualBasic.Information.TypeName(CurrentItem.Object)
If TypeName = "ProjectItem" Then
Dim projectitem As EnvDTE.ProjectItem = CType(CurrentItem.Object, EnvDTE.ProjectItem)
Dim i As Integer = 1
While i <= projectitem.FileCount
If projectitem.FileNames(i) = FileName Then
SolutionExplorerPath = CurrentItem.Name
Return CurrentItem
End If
i = i + 1
End While
End If
Dim ChildItem As UIHierarchyItem = FindItem(CurrentItem.UIHierarchyItems, FileName, SolutionExplorerPath)
If Not ChildItem Is Nothing Then
SolutionExplorerPath = CurrentItem.Name + "\" + SolutionExplorerPath
Return ChildItem
End If
Next
End Function
End Module
Original Source here
在Visual Studio 2010/2012中,您可以使用此扩展程序 (链接)。 它添加了在Solution Explorer工具栏和代码上下文菜单中同步的选项。