简体   繁体   中英

Display solution/file path in the Visual Studio IDE

I frequently work with multiple instances of Visual Studio, often working on different branches of the same solution.

Visual C++ 6.0 used 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).

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?

This is a extension available in the online gallery specifically tailored for this job. Checkout Labs > Visual Studio Extension: Customize Visual Studio Window Title .

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

You just have to add a little Visual Basic macro to the EvironmentEvents macro section and restart 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.

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.

More details: http://vscommands.com/releasenotes/3.6.8.0 and http://vscommands.com/releasenotes/3.6.9.0

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.

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.

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

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.

How to customise the Visual Studio window title

Install the Customize Visual Studio Window Title plugin.

After installing the extension, the settings can be found in the menu.

Menu ToolsOptionsCustomize VS Window Title .

More information

Customize Visual Studio Window Title is a lightweight extension to Visual Studio, which allows you to change the window title to include a folder tree:

在此处输入图片说明

Features

  • A configurable minimum and maximum depth distance from the solution/project file
  • Allows the use of special tags to help with many other possible scenarios, which include Git , Mercurial , and TFS .

I am using VSCommands 10 to show the full path of the solution file open.

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:

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

正如Dan在评论中也提到的, 页脚扩展的文件路径具有相同的目的。

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.

I wrote a blog entry here about it...

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

For the people that didn't get the VB method to work (like me) you can use a plugin:

Customize Visual Studio Window Title

It was tested it in Visual Studio 2008 Ultimate. You can configure it in the Options menu of Visual Studio.

Related note: As an alternative, for Visual Studio 2005 you can use the command menu FileAdvanced Save Options . The dialog displays the full path of the current file, and you are able to copy the text.

If you are using Visual Studio 2010 or above you can you the extension "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

TabsStudio | US$49

It is a pretty good (although paid) Visual Studio extension that provides:

  • Tab grouping
  • Tab coloring
  • Title transformation
  • Lots of customization and extensions

标签工作室截图

File Path On Footer | Free

It displays the full file path on the bottom of the editor window:

页脚屏幕截图上的文件路径

Honorable Mention: Visual Studio Code

Visual Studio Code version 1.26 implemented breadcrumbs which displays the file path in a separate row at the top of the editor window when using tabs or inline the file name when in its own window.

Visual Studio Code 面包屑屏幕截图

File > Preferences > Settings >> Window:Title

I just changed ${activeEditorShort} => ${activeEditorLong}

within the setting: ${dirty}${activeEditorLong}${separator}${rootName}${separator}${appName}

Worked immediately when I clicked a file.

Great help right in the setting ...

Window: Title -- Controls the window title based on the active editor. Variables are substituted based on the context:

${activeEditorShort}: the file name (eg myFile.txt).

${activeEditorMedium}: the path of the file relative to the workspace folder (eg myFolder/myFileFolder/myFile.txt).

...

Visual Studio Code Version: 1.56.2 Date: 2021-05-12

I found one reference saying this existed since 2017.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM