我经常使用Visual Studio的多个实例,通常在同一解决方案的不同分支上工作。
VC6用于在标题栏中显示当前源文件的完整路径,但Visual Studio 2005似乎不会这样做。这使得它比我应该解决我正在查看的解决方案的哪个分支更加尴尬(我知道的最快的方法是将鼠标悬停在选项卡上,以便将源文件的路径作为工具提示)。
有没有办法让完整的解决方案或文件路径进入标题栏,或者至少在某个地方始终可见,这样我就能快速分辨出哪个分支被加载到每个实例中?
没有本地方法可以做到这一点,但您可以使用宏来实现它。详细描述如下:http://www.helixoft.com/blog/archives/32
您只需要在EvironmentEvents宏部分添加一点VBA宏并重新启动VS.
注意:首次加载VS时,路径不会显示,但每当您更改正在查看的文件时,路径都会显示。可能有办法解决这个问题,但这似乎不是什么大问题。
如果您使用的是VS2010或更高版本,则可以使用扩展名“Visual Studio Window Title Changer”。安装它并使用以下“窗口标题设置”表达式来显示解决方案路径:
“sln_dir +”/“+ orig_title”
使用扩展管理器下载并安装扩展。有关扩展的详细信息以及如何使用它,请访问:
https://visualstudiogallery.msdn.microsoft.com/2e8ebfe4-023f-4c4d-9b7a-d05bbc5cb239?SRC=VSIDE
相关说明:作为替代方案,对于Visual Studio 2005,您可以使用命令“文件” - >“高级保存选项”。该对话框显示当前文件的完整路径,您可以复制文本。
正如Dan在评论中也提到的那样,File Path On Footer扩展也有同样的目的。
是一个非常好的(虽然付费)VS扩展,提供:
显示编辑器窗口底部的完整文件路径
VS代码version 1.26 implemented breadcrumbs在使用选项卡时在编辑器窗口顶部的单独行中显示文件路径,或者在其自己的窗口中内联文件名。
这是专为此工作量身定制的在线图库中的扩展。结帐http://erwinmayer.com/labs/visual-studio-2010-extension-rename-visual-studio-window-title/
查看最新版本的VSCommands 2010 Lite。它引入了一个名为Friendly Solution Name的功能,您可以在其中将其设置为在Visual Studio主窗口标题中显示解决方案文件路径(或其任何部分)。更多细节:http://vscommands.com/releasenotes/3.6.8.0和http://vscommands.com/releasenotes/3.6.9.0
对于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
确实很尴尬。悬停在选项卡上确实是少数有用的东西之一。替代方案:右键单击文件选项卡:http://weblogs.asp.net/piseth/archive/2008/11/08/find-your-file-path-in-visual-studio.aspx似乎我们必须这样做
我正在使用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窗口标题
安装Customize Visual Studio Window Title插件。
安装扩展程序后,可以在菜单中找到设置。
Tools ► Options ► Customize VS Window Title
。
更多信息
Customize Visual Studio Window Title
是Visual Studio的轻量级扩展,它允许您更改窗口标题以包含文件夹树
特征
Git
,Mercurial
和TFS
。使用MKLINK命令创建指向现有解决方案的链接。至于Visual Studio关注它使用链接文件,但任何更改都会转到底层的.sln文件。
我在这里写了一篇关于它的博客文章......
对于没有使用VB方法的人(像我一样),你可以使用一个插件:
http://visualstudiogallery.msdn.microsoft.com/f3f23845-5b1e-4811-882f-60b7181fa6d6
在VS2008 Ultimate中测试过。您可以在VS的“选项”菜单中进行配置。