Issue
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?
Solution
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:
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:
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:1234Set 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.
Answered By - brgerner Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.