I know there are already several questions about renaming files by using a version control system. But I did not found a satisfactory answer to the special version control system Perforce.
My question:
Is there a plug-in/solution which keeps the version history of my C# code files when I renaming it within Visual Studio?
Edit: Currently I am using VS2P4 plug-in.
Edit2: I have found a little shorter way to rename a file:
- Open containing folder in Explorer (in Solution Explorer right-click Open in Windows Explorer).
- Select file and right-click Perforce->Show in P4V.
- Do the normal rename/move action with selected file.
That scenario is shorter than navigating in Perforce Depot in P4V until I find the right file. But of course I am looking for a shorter way.
Edit3: Is there a way to directly do "Show in P4V" with file selection within VS?
Macro
I have a good solution now. Just handle macro event SolutionItemsEvents_ItemRenamed.
This is done by open Macros IDE by clicking Tools->Macros->Macros IDE. Then add following event handler to your macro project:
See screenshot:
As you can see it just calls a "p4 move -k". "-k" option is needed because after a rename the old file is already deleted, so Perforce would throw an error without "-k". "-k" causes Perforce to rename the file on server only.
If you get Perforce connection errors you need to add a P4CONFIG file where connection is defined. This is done by:
Add file p4config.txt to the directory of your project (or any of its parent directories) with content:
P4CLIENT=your workspace
P4USER=user
P4PORT=p4server:1234
Set environment variable P4CONFIG=p4config.txt
Now you can change your files by any way (Solution Explorer Item->Rename, Solution Explorer Item->F2, ReSharper's Rename file to match type name, ReSharper's class Rename (Ctrl+R,R),...).
But keep in mind: I have problems if I try to edit and rename same file in one chek-in and if I rename a file while another person has checked-out same file.
There's a new Visual Studio plugin for Perforce that will be out in beta shortly. It does have support for the built-in Visual Studio rename operation, and also works well with Resharper.
Until it's out I'm afraid the existing solutions are a bit clunky.
You can save yourself a step in that process by setting up an external tool in VS (Tools->External Tools) to open perforce to the document you have open. Not ideal, but closer to what you want.
The Visual Studio Plugin provides excellent integration with the Visual Studio. All renaming operations work well and the history is tracked ok.