visual-studio 在 Visual Studio IDE 中显示解决方案/文件路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display solution/file path in the Visual Studio IDE
提问by James Sutherland
I frequently work with multiple instances of Visual Studio, often working on different branches of the same solution.
我经常使用 Visual Studio 的多个实例,经常在同一解决方案的不同分支上工作。
Visual C++ 6.0used to display the full path of the current source file in its title bar, but Visual Studio 2005 doesn't appear to do this. This makes it slightly more awkward than it should be to work out which branch of the solution I'm currently looking at (the quickest way I know of is to hover over a tab so you get the source file's path as a tooltip).
Visual C++ 6.0曾经在其标题栏中显示当前源文件的完整路径,但 Visual Studio 2005 似乎没有这样做。这使得找出我当前正在查看的解决方案的哪个分支比应该更尴尬(我所知道的最快方法是将鼠标悬停在选项卡上,以便您获得源文件的路径作为工具提示)。
Is there a way to get the full solution or file path into the title bar, or at least somewhere that's always visible, so I can quickly tell which branch is loaded into each instance?
有没有办法将完整的解决方案或文件路径放入标题栏,或者至少在始终可见的某个地方,以便我可以快速判断哪个分支加载到每个实例中?
采纳答案by Adam Haile
There is not a native way to do it, but you can achieve it with a macro. The details are described here in full: How To Show Full File Path (or Anything Else) in VS 2005 Title Bar
没有本地方法可以做到这一点,但您可以使用宏来实现。此处详细描述了详细信息:如何在 VS 2005 标题栏中显示完整文件路径(或其他任何内容)
You just have to add a little Visual Basic macro to the EvironmentEvents macro section and restart Visual Studio.
您只需要向 EvironmentEvents 宏部分添加一个小的 Visual Basic 宏并重新启动 Visual Studio。
Note: The path will not show up when you first load Visual Studio, but it will whenever you change which file you are viewing. There is probably a way to fix this, but it doesn't seem like a big deal.
注意:当您第一次加载 Visual Studio 时,该路径不会显示,但只要您更改正在查看的文件,就会显示该路径。可能有一种方法可以解决这个问题,但这似乎没什么大不了的。
回答by Bruno Vinicius
This is a extension available in the online gallery specifically tailored for this job. Checkout Labs > Visual Studio Extension: Customize Visual Studio Window Title.
这是在线图库中专门为此工作量身定制的扩展程序。结帐实验室 > Visual Studio 扩展:自定义 Visual Studio 窗口标题。
回答by Registered User
Check out the latest release of VSCommands 2010 Lite. It introduced a feature called Friendly Solution Name where you can set it to display the solution file path (or any part of it) in Visual Studio's main window title.
查看VSCommands 2010 Lite的最新版本。它引入了一个称为友好解决方案名称的功能,您可以在其中设置它以在 Visual Studio 的主窗口标题中显示解决方案文件路径(或其任何部分)。
More details: http://vscommands.com/releasenotes/3.6.8.0and http://vscommands.com/releasenotes/3.6.9.0
更多详情:http: //vscommands.com/releasenotes/3.6.8.0和http://vscommands.com/releasenotes/3.6.9.0
回答by Drew Miller
For Visual Studio 2008, a slightly better way to write the macro from the accepted answer is to use the Solution events instead of the document ones - this lets you always edit the title bar, even if you don't have a document selected.
对于 Visual Studio 2008,从接受的答案中编写宏的更好方法是使用解决方案事件而不是文档事件 - 这使您始终可以编辑标题栏,即使您没有选择文档。
Here's the macro my coworker and I put together based on the other one - you'll want to change lines 15-18 to pull your branch name from the source directory for however you're set up.
这是我的同事和我根据另一个宏组合在一起的宏 - 您需要更改第 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
回答by Drew Miller
It's awkward indeed. Hovering on the tab is indeed one of the few things useful.
确实很别扭。将鼠标悬停在选项卡上确实是少数有用的事情之一。
Alternative: right click on the file tab: Find your File Path in Visual Studio. It seems we have to do with that.
替代方法:右键单击文件选项卡:在 Visual Studio 中查找文件路径。看来我们必须这样做。
回答by superlogical
I am using VSCommands 10 to show the full path of the solution file open.
我正在使用 VSCommands 10 来显示打开的解决方案文件的完整路径。
Friendly Name: {repo}
Solution Path Regex: (?<repo>.*)
Now my main title window looks like this:
现在我的主标题窗口如下所示:
c:\repositories\acme.marketplace.trunk\Acme.Marketplace.web\Acme.Marketplace.Web.sln
I can quickly glance and see that I am working in the trunk folder or a rc folder because we use Mercurial (Hg) and keep separate folders for trunk, rc, preprod, prod like this:
我可以快速浏览并看到我在主干文件夹或 rc 文件夹中工作,因为我们使用 Mercurial (Hg) 并为主干、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
回答by YanZhiwei
How to customise the Visual Studio window title
如何自定义 Visual Studio 窗口标题
Install the Customize Visual Studio Window Titleplugin.
After installing the extension, the settings can be found in the menu.
安装扩展后,可以在菜单中找到设置。
Menu Tools? Options? Customize VS Window Title.
菜单工具?选项?自定义 VS 窗口标题。
More information
更多信息
Customize Visual Studio Window Titleis a lightweight extension to Visual Studio, which allows you to change the window title to include a folder tree:
自定义 Visual Studio 窗口标题是Visual Studio的轻量级扩展,它允许您更改窗口标题以包含文件夹树:
Features
特征
回答by Muad'Dib
If you are using Visual Studio 2010 or above you can you the extension "Visual Studio Window Title Changer".
如果您使用的是 Visual Studio 2010 或更高版本,则可以使用扩展名“Visual Studio Window Title Changer”。
Install this and use the following 'Window Title Setup' expression to display the solution path:
安装它并使用以下“窗口标题设置”表达式来显示解决方案路径:
'sln_dir + "/" + orig_title'
Use the extension manager to download and install the extension. Details of the extension and how to use it can be found here:
使用扩展管理器下载并安装扩展。可以在此处找到扩展程序的详细信息以及如何使用它:
https://visualstudiogallery.msdn.microsoft.com/2e8ebfe4-023f-4c4d-9b7a-d05bbc5cb239?SRC=VSIDE
https://visualstudiogallery.msdn.microsoft.com/2e8ebfe4-023f-4c4d-9b7a-d05bbc5cb239?SRC=VSIDE
回答by Leroy
For the people that didn't get the VB method to work (like me) you can use a plugin:
对于没有使用 VB 方法的人(如我),您可以使用插件:
Customize Visual Studio Window Title
It was tested it in Visual Studio 2008 Ultimate. You can configure it in the Optionsmenu of Visual Studio.
它在 Visual Studio 2008 Ultimate 中进行了测试。您可以在Visual Studio的“选项”菜单中对其进行配置。
回答by Lee WIllis
Use the MKLINK command to create a link to your existing solution. As far as Visual Studio is concerned, it's working with the link file, but any changes go to the underlying .sln file.
使用 MKLINK 命令创建指向现有解决方案的链接。就 Visual Studio 而言,它正在处理链接文件,但任何更改都会转到基础 .sln 文件。
I wrote a blog entry here about it...
我在这里写了一篇关于它的博客文章......


