【问题标题】:Display solution/file path in the Visual Studio IDE在 Visual Studio IDE 中显示解决方案/文件路径
【发布时间】:2010-09-07 00:39:43
【问题描述】:

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

Visual C++ 6.0 用于在其标题栏中显示当前源文件的完整路径,但 Visual Studio 2005 似乎没有这样做。这使得计算出我当前正在查看的解决方案的哪个分支变得比它应该更尴尬(我所知道的最快的方法是将鼠标悬停在一个选项卡上,这样您就可以将源文件的路径作为工具提示)。

有没有办法将完整的解决方案或文件路径放入标题栏中,或者至少在某个始终可见的地方,以便我可以快速判断哪个分支加载到每个实例中?

【问题讨论】:

  • 11 年,仍然无法开箱即用:-/
  • 首选项 > 窗口:标题。不需要插件。 => 至少从 2017 年就存在了。
  • @JasonLeMonier,我在 Visual Studio 中找不到此设置,但我可以在 Visual Studio Code 中找到它,你是不是把它们弄混了?也许您可以发布一个完整的答案以使其更清晰。编辑 - 刚刚注意到您确实发布了答案,很好。

标签: visual-studio projects-and-solutions


【解决方案1】:

这是专门为这项工作量身定制的在线图库中的扩展程序。结帐Labs > Visual Studio Extension: Customize Visual Studio Window Title

【讨论】:

  • 太棒了。简约的扩展,只是工作。无需配置。
  • 2015 年也可以使用
  • 2017 年也可以使用
  • 也适用于 2019 年。可选Re-enable the Window Title Bar 或只是观察您在任务栏中的更改。在 v16.4.2 上测试。
  • 首选项 > 窗口:标题。无需插件。
【解决方案2】:

没有本地方法可以做到这一点,但您可以使用宏来实现。详细信息在此处完整描述:How To Show Full File Path (or Anything Else) in VS 2005 Title Bar

您只需将一点 Visual Basic 宏添加到 EvironmentEvents 宏部分并重新启动 Visual Studio。

注意:当您首次加载 Visual Studio 时,该路径不会显示,但只要您更改正在查看的文件,它就会显示。可能有办法解决这个问题,但似乎没什么大不了的。

【讨论】:

  • File Path On Footer 也是一个不错的扩展
  • @dan ...但是在编辑器底部吃了一行(不在状态栏中(你知道,调试时蓝色变为橙色))。考虑到它,尤其是小屏幕等。无论如何,谢谢你的指点。
【解决方案3】:

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

更多详情:http://vscommands.com/releasenotes/3.6.8.0http://vscommands.com/releasenotes/3.6.9.0

【讨论】:

【解决方案4】:

对于 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

【讨论】:

    【解决方案5】:

    确实很尴尬。将鼠标悬停在标签上确实是少数有用的事情之一。

    替代方法:右键单击文件选项卡:Find your File Path in Visual Studio。看来我们必须这样做。

    【讨论】:

      【解决方案6】:

      如何自定义 Visual Studio 窗口标题

      安装Customize Visual Studio Window Title 插件。

      安装扩展后,可以在菜单中找到设置。

      菜单工具选项自定义 VS 窗口标题

      更多信息

      自定义 Visual Studio 窗口标题是 Visual Studio 的轻量级扩展,它允许您更改窗口标题以包含文件夹树:

      特点

      • 与解决方案/项目文件的可配置最小和最大深度距离
      • 允许使用特殊标签来帮助处理许多其他可能的情况,包括GitMercurialTFS

      【讨论】:

      • 虽然此代码可能会回答问题,但提供有关它如何和/或为什么解决问题的额外上下文将提高​​答案的长期价值。请阅读此how-to-answer 以提供高质量的答案。
      • 首选项 > 窗口:标题。无需插件。
      【解决方案7】:

      我正在使用 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
      

      【讨论】:

      【解决方案8】:

      正如Dan 也在评论中提到的那样,File Path On Footer 扩展名具有相同的目的。

      【讨论】:

        【解决方案9】:

        相关说明:作为替代方案,对于 Visual Studio 2005,您可以使用命令菜单文件高级保存选项。对话框显示当前文件的完整路径,您可以复制文本。

        【讨论】:

          【解决方案10】:

          使用 MKLINK 命令创建指向现有解决方案的链接。就 Visual Studio 而言,它正在使用链接文件,但任何更改都会转到底层 .sln 文件。

          我在这里写了一篇关于它的博客文章...

          http://willissoftware.com/?p=72

          【讨论】:

          • 链接已损坏(“我们无法连接到 www.willissoftware.com 上的服务器。”)。域名过期了?
          • 这个答案对于断开的链接不是很有用。
          【解决方案11】:

          对于没有使用 VB 方法的人(比如我),您可以使用插件:

          Customize Visual Studio Window Title

          在 Visual Studio 2008 Ultimate 中对其进行了测试。您可以在 Visual Studio 的 选项 菜单中进行配置。

          【讨论】:

          • 首选项 > 窗口:标题。无需插件。
          【解决方案12】:

          TabsStudio | 49 美元

          这是一个相当不错的(虽然是付费的)Visual Studio 扩展,它提供:

          • 标签分组
          • 标签着色
          • 标题转换
          • 大量自定义和扩展

          File Path On Footer |免费

          它在编辑器窗口底部显示完整的文件路径:

          荣誉奖:Visual Studio 代码

          Visual Studio Code version 1.26 implemented breadcrumbs 在使用选项卡时在编辑器窗口顶部的单独行中显示文件路径,或在其自己的窗口中内联文件名。

          【讨论】:

            【解决方案13】:

            如果您使用的是 Visual Studio 2010 或更高版本,您可以添加“Visual Studio Window Title Changer”扩展。

            安装它并使用以下“窗口标题设置”表达式来显示解决方案路径:

            'sln_dir + "/" + orig_title'
            

            使用扩展管理器下载并安装扩展。可以在此处找到扩展程序的详细信息以及如何使用它:

            https://visualstudiogallery.msdn.microsoft.com/2e8ebfe4-023f-4c4d-9b7a-d05bbc5cb239?SRC=VSIDE

            【讨论】:

            • 链接已损坏 (404)。
            • 首选项 > 窗口:标题。无需插件。
            【解决方案14】:

            文件>首选项>设置>>窗口:标题

            我刚刚更改了 ${activeEditorShort} => ${activeEditorLong}

            在设置内: ${dirty}${activeEditorLong}${separator}${rootName}${separator}${appName}

            当我点击一个文件时立即工作。

            在设置中的帮助很大...

            窗口:标题 -- 根据活动编辑器控制窗口标题。根据上下文替换变量:

            ${activeEditorShort}:文件名(例如 myFile.txt)。

            ${activeEditorMedium}:文件相对于工作区文件夹的路径(例如 myFolder/myFileFolder/myFile.txt)。

            ...

            Visual Studio 代码 版本:1.56.2 日期:2021-05-12

            我发现一个参考资料说这自 2017 年以来就存在。

            【讨论】:

            • 问题是针对 Visual Studio,而不是针对 Visual Studio Code。
            猜你喜欢
            • 2017-10-03
            • 2016-08-15
            • 1970-01-01
            • 1970-01-01
            • 2017-09-02
            • 2010-10-16
            • 2015-11-28
            • 1970-01-01
            相关资源
            最近更新 更多