在Visual Studio IDE中显示解决方案/文件路径

Jam*_*and 76 projects-and-solutions visual-studio

我经常使用Visual Studio的多个实例,通常在同一解决方案的不同分支上工作.

VC6用于在标题栏中显示当前源文件的完整路径,但Visual Studio 2005似乎不会这样做.这使得它比我应该解决我正在查看的解决方案的哪个分支更加尴尬(我知道的最快的方法是将鼠标悬停在选项卡上,以便将源文件的路径作为工具提示).

有没有办法让完整的解决方案或文件路径进入标题栏,或者至少在某个地方始终可见,这样我就能快速分辨出哪个分支被加载到每个实例中?

小智 30

这是专为此工作量身定制的在线图库中的扩展.结帐http://erwinmayer.com/labs/visual-studio-2010-extension-rename-visual-studio-window-title/

  • 真棒.简单的扩展,只是工作.无需配置. (2认同)
  • 也适用于VS2013. (2认同)
  • 也适用于2015年 (2认同)
  • 也适用于 2017 年 (2认同)
  • 2019 年也适用。(可选)[重新启用窗口标题栏](/sf/ask/3754544531/) 或只是观察任务栏中的更改。在 v16.4.2 上测试。 (2认同)

Ada*_*ile 24

没有本地方法可以做到这一点,但您可以使用宏来实现它.详细信息请参见此处:http://www.helixoft.com/blog/archives/32

您只需要在EvironmentEvents宏部分添加一点VB宏并重新启动VS.

注意:首次加载VS时,路径不会显示,但每当您更改正在查看的文件时,路径都会显示.可能有办法解决这个问题,但这似乎不是什么大问题.

  • [文件路径在页脚](https://visualstudiogallery.msdn.microsoft.com/d9fc97d4-3b42-4b56-ba47-23f8b81ebd17/)也是一个很好的扩展 (3认同)
  • @dan ...但在编辑器底部吃一行(不在状态栏中(您知道,调试时蓝色变为橙色))。考虑到它,特别是对于小屏幕等。无论如何,谢谢你的指点。 (2认同)

小智 17

查看最新版本的VSCommands 2010 Lite.它引入了一个名为Friendly Solution Name的功能,您可以在其中将其设置为在Visual Studio主窗口标题中显示解决方案文件路径(或其任何部分).更多细节:http://vscommands.com/releasenotes/3.6.8.0http://vscommands.com/releasenotes/3.6.9.0

  • 似乎已经略微移动到这里:http://vscommands.squaredinfinity.com/ (2认同)

Dre*_*ler 5

对于2008年,从上面接受的答案中编写宏的稍微好一点的方法是使用解决方案事件而不是文档事件 - 这使您可以随时编辑标题栏,即使您没有选择文档.这是宏我的同事和我基于另一个放在一起的你 - 你想要改变第15-18行来从源目录中提取您的分支名称,但是你已经设置好了.

01  Private timer As System.Threading.Timer
02  Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, ByVal lpstring As String) As Boolean
03   
04  Private _branchName As String = String.Empty
05  Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened
06      Try
07          If timer Is Nothing Then
08              ' Create timer which refreshes the caption because
09              ' IDE resets the caption very often
10              Dim autoEvent As New System.Threading.AutoResetEvent(False)
11              Dim timerDelegate As System.Threading.TimerCallback = _
12                  AddressOf tick
13              timer = New System.Threading.Timer(timerDelegate, autoEvent, 0, 25)
14          End If
15          Dim sourceIndex As Integer = DTE.Solution.FullName.IndexOf("\Source")
16          Dim shortTitle As String = DTE.Solution.FullName.Substring(0, sourceIndex)
17          Dim lastIndex As Integer = shortTitle.LastIndexOf("\")
18          _branchName = shortTitle.Substring(lastIndex + 1)
19          showTitle(_branchName)
20      Catch ex As Exception
21   
22      End Try
23  End Sub
24   
25  Private Sub SolutionEvents_BeforeClosing() Handles SolutionEvents.BeforeClosing
26      If Not timer Is Nothing Then
27          timer.Dispose()
28      End If
29  End Sub
30   
31   
32  ''' <summary>Dispose the timer on IDE shutdown.</summary>
33  Public Sub DTEEvents_OnBeginShutdown() Handles DTEEvents.OnBeginShutdown
34      If Not timer Is Nothing Then
35          timer.Dispose()
36      End If
37  End Sub
38   
39  '''<summary>Called by timer.</summary>
40  Public Sub tick(ByVal state As Object)
41      Try
42          showTitle(_branchName)
43      Catch ex As System.Exception
44      End Try
45  End Sub
46   
47  '''<summary>Shows the title in main window.</summary>
48  Private Sub showTitle(ByVal title As String)
49      SetWindowText(New System.IntPtr(DTE.MainWindow.HWnd), title & " - " & DTE.Name)
50  End Sub
Run Code Online (Sandbox Code Playgroud)