我经常使用 Visual Studio 的多个实例,经常在同一解决方案的不同分支上工作。
Visual C++ 6.0曾经在其标题栏中显示当前源文件的完整路径,但 Visual Studio 2005 似乎没有这样做。这使得计算出我当前正在查看的解决方案的哪个分支(我所知道的最快方法是将鼠标悬停在选项卡上,以便您将源文件的路径作为工具提示获取)比它应该稍微尴尬一些。
有没有办法将完整的解决方案或文件路径放入标题栏中,或者至少在某个始终可见的地方,这样我就可以快速判断哪个分支被加载到每个实例中?
我经常使用 Visual Studio 的多个实例,经常在同一解决方案的不同分支上工作。
Visual C++ 6.0曾经在其标题栏中显示当前源文件的完整路径,但 Visual Studio 2005 似乎没有这样做。这使得计算出我当前正在查看的解决方案的哪个分支(我所知道的最快方法是将鼠标悬停在选项卡上,以便您将源文件的路径作为工具提示获取)比它应该稍微尴尬一些。
有没有办法将完整的解决方案或文件路径放入标题栏中,或者至少在某个始终可见的地方,这样我就可以快速判断哪个分支被加载到每个实例中?
这是专门为这项工作量身定制的在线图库中的一个扩展。结帐实验室 > Visual Studio 扩展:自定义 Visual Studio 窗口标题。
没有本地方法可以做到这一点,但您可以使用宏来实现。此处详细描述了详细信息:How To Show Full File Path (or Anything Else) in VS 2005 Title Bar
您只需将一点 Visual Basic 宏添加到 EvironmentEvents 宏部分并重新启动 Visual Studio。
注意:首次加载 Visual Studio 时不会显示该路径,但只要更改正在查看的文件就会显示该路径。可能有一种方法可以解决这个问题,但这似乎没什么大不了的。
查看最新版本的VSCommands 2010 Lite。它引入了一个名为 Friendly Solution Name 的功能,您可以将其设置为在 Visual Studio 的主窗口标题中显示解决方案文件路径(或其任何部分)。
更多详细信息: http: //vscommands.com/releasenotes/3.6.8.0和http://vscommands.com/releasenotes/3.6.9.0
对于 Visual Studio 2008,从接受的答案编写宏的更好方法是使用解决方案事件而不是文档事件 - 这使您始终可以编辑标题栏,即使您没有选择文档。
这是我的同事和我根据另一个宏放在一起的宏 - 您需要更改第 15-18 行以从源目录中提取您的分支名称,无论您是如何设置的。
Private timer As System.Threading.Timer
Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, ByVal lpstring As String) As Boolean
Private _branchName As String = String.Empty
Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened
Try
If timer Is Nothing Then
' Create timer which refreshes the caption because
' IDE resets the caption very often
Dim autoEvent As New System.Threading.AutoResetEvent(False)
Dim timerDelegate As System.Threading.TimerCallback = _
AddressOf tick
timer = New System.Threading.Timer(timerDelegate, autoEvent, 0, 25)
End If
Dim sourceIndex As Integer = DTE.Solution.FullName.IndexOf("\Source")
Dim shortTitle As String = DTE.Solution.FullName.Substring(0, sourceIndex)
Dim lastIndex As Integer = shortTitle.LastIndexOf("\")
_branchName = shortTitle.Substring(lastIndex + 1)
showTitle(_branchName)
Catch ex As Exception
End Try
End Sub
Private Sub SolutionEvents_BeforeClosing() Handles SolutionEvents.BeforeClosing
If Not timer Is Nothing Then
timer.Dispose()
End If
End Sub
''' <summary>Dispose the timer on IDE shutdown.</summary>
Public Sub DTEEvents_OnBeginShutdown() Handles DTEEvents.OnBeginShutdown
If Not timer Is Nothing Then
timer.Dispose()
End If
End Sub
'''<summary>Called by timer.</summary>
Public Sub tick(ByVal state As Object)
Try
showTitle(_branchName)
Catch ex As System.Exception
End Try
End Sub
'''<summary>Shows the title in main window.</summary>
Private Sub showTitle(ByVal title As String)
SetWindowText(New System.IntPtr(DTE.MainWindow.HWnd), title & " - " & DTE.Name)
End Sub
确实很尴尬。将鼠标悬停在选项卡上确实是少数有用的事情之一。
替代方法:右键单击文件选项卡:在 Visual Studio 中查找文件路径。看来我们必须这样做。
安装扩展程序后,可以在菜单中找到设置。
菜单工具►选项►自定义 VS 窗口标题。
更多信息
自定义 Visual Studio 窗口标题是 Visual Studio 的轻量级扩展,它允许您更改窗口标题以包含文件夹树:
我正在使用 VSCommands 10 来显示打开的解决方案文件的完整路径。
Friendly Name: {repo}
Solution Path Regex: (?<repo>.*)
现在我的主标题窗口如下所示:
c:\repositories\acme.marketplace.trunk\Acme.Marketplace.web\Acme.Marketplace.Web.sln
我可以快速浏览并看到我在trunk文件夹或rc文件夹中工作,因为我们使用Mercurial(Hg)并为trunk,rc,preprod,prod保留单独的文件夹,如下所示:
c:\repositories\acme.marketplace.rc1
c:\repositories\acme.marketplace.rc2
c:\repositories\acme.marketplace.trunk
c:\repositories\acme.marketplace.preprod
c:\repositories\acme.marketplace.prod
相关说明:作为替代方案,对于 Visual Studio 2005,您可以使用命令菜单File → Advanced Save Options。该对话框显示当前文件的完整路径,您可以复制文本。
使用 MKLINK 命令创建指向现有解决方案的链接。就 Visual Studio 而言,它正在使用链接文件,但任何更改都会转到基础 .sln 文件。
我在这里写了一篇关于它的博客文章......
对于没有使用 VB 方法的人(比如我),您可以使用插件:
它在 Visual Studio 2008 Ultimate 中进行了测试。您可以在Visual Studio的“选项”菜单中对其进行配置。
这是一个相当不错的(虽然是付费的)Visual Studio 扩展,它提供:
它在编辑器窗口的底部显示完整的文件路径:
Visual Studio Code 1.26 版实现了面包屑,当使用选项卡时在编辑器窗口顶部的单独行中显示文件路径,或者在其自己的窗口中内联文件名。
如果您使用的是 Visual Studio 2010 或更高版本,您可以扩展“Visual Studio Window Title Changer”。
安装它并使用以下“窗口标题设置”表达式来显示解决方案路径:
'sln_dir + "/" + orig_title'
使用扩展管理器下载并安装扩展。可以在此处找到扩展程序的详细信息以及如何使用它:
https://visualstudiogallery.msdn.microsoft.com/2e8ebfe4-023f-4c4d-9b7a-d05bbc5cb239?SRC=VSIDE
文件 > 首选项 > 设置 >> 窗口:标题
我刚刚更改了 ${activeEditorShort} => ${activeEditorLong}
在设置中:${dirty}${activeEditorLong}${separator}${rootName}${separator}${appName}
当我点击一个文件时立即工作。
在设置中提供了很大的帮助...
Window: Title -- 根据活动编辑器控制窗口标题。根据上下文替换变量:
${activeEditorShort}:文件名(例如 myFile.txt)。
${activeEditorMedium}:文件相对于工作区文件夹的路径(例如myFolder/myFileFolder/myFile.txt)。
...
Visual Studio 代码版本:1.56.2 日期:2021-05-12
我发现一个参考资料说这自 2017 年以来就存在。