How to keep a history of changes when renaming files in Visual Studio using Perforce

I know that there are several questions about renaming files using version control. But I did not find a satisfactory answer to the special version control system Perforce .
My question is: Is there a plug-in / solution that saves the version history of my C # code files when renaming in Visual Studio?

Edit: I am currently using the VS2P4 plugin.

Edit2: I found a slightly shorter way to rename the file:

  • Open the containing folder in Explorer (in the Solution Explorer, right-click Open in Windows Explorer).
  • Select the file and right-click Perforce-> Show in P4V.
  • Perform normal renaming / moving with the selected file.

This scenario is shorter than switching to Perforce Depot in P4V until I find the file I need. But of course I'm looking for a shorter way.

Edit3: Is there a direct way to "Show in P4V" with selecting a file in VS?

+5
source share
4 answers

Macro

I have a good solution now. Just handle the macro event SolutionItemsEvents_ItemRenamed.
This is done using the open Macros IDE by clicking Tools-> Macros-> Macros IDE. Then add the following event handler to your macro project:

Private Sub SolutionItemsEvents_ItemRenamed(ByVal ProjectItem As EnvDTE.ProjectItem, ByVal OldName As String) Handles SolutionItemsEvents.ItemRenamed Dim process As System.Diagnostics.Process process.Start("p4", "move -k " & ProjectItem.Properties.Parent.Document.Path & "\\" & OldName & " " & ProjectItem.Document.Path) End Sub 

See screenshot: enter image description here

As you can see, this simply calls "p4 move -k". The "-k" option is necessary because after renaming the old file is already deleted, so Perforce will throw an error without the "-k". "-k" forces Perforce to rename the file only on the server.

If you get Perforce connection errors , you need to add the P4CONFIG file where the connection is defined. This is done by:

  • Add the p4config.txt file to the directory of your project (or any of its parent directories) with the content:

    P4CLIENT = your workspace
    P4USER = user
    P4PORT = p4server: 1234

  • Set environment variable P4CONFIG = p4config.txt

Now you can somehow change your files (Solution Explorer Item-> Rename, Solution Explorer Item-> F2, ReSharper Rename the file to match the type name, the ReSharper class Rename (Ctrl + R, R), ...),

But keep in mind: I am having problems if I try to edit and rename the same file in the same mode, and if I rename the file while the other person has the extracted file.

0
source

There will be a new Visual Studio plugin for Perforce, which will soon be available in beta. It supports the built-in Visual Studio rename operation, and also works well with Resharper.

While this is not the case, I am afraid that existing solutions are a bit awkward.

+6
source

You can save yourself a step in this process by setting up an external tool in VS (Tools-> External Tools) to open perforce to an open document. Not perfect, but closer to what you want.

 Command: p4v.exe Arguments: -s $(ItemPath) Initial Directory: $(ItemDir) 
+1
source

Visual Studio Plugin provides excellent integration with Visual Studio. All renaming operations work well, and history is tracked fine.

0
source

All Articles