如何在使用 Perforce 在 Visual Studio 中重命名文件时保留更改历史记录 [英] How to keep change history while renaming files in Visual Studio using Perforce
问题描述
我知道已经有几个关于使用版本控制系统重命名文件的问题.但是我没有找到对特殊版本控制系统Perforce的满意答案.
我的问题:当我在 Visual Studio 中重命名 C# 代码文件时,是否有插件/解决方案可以保留它的版本历史记录?
目前我使用的是 VS2P4 插件.
我找到了一种更短的重命名文件的方法:
- 在资源管理器中打开包含文件夹(在解决方案资源管理器中右键单击在 Windows 资源管理器中打开).
- 选择文件并右键单击 Perforce->在 P4V 中显示.
- 对所选文件执行正常的重命名/移动操作.
这种情况比在 P4V 中的 Perforce Depot 中导航要短,直到我找到正确的文件.但当然我正在寻找一种更短的方式.
Edit3:有没有办法在 VS 中通过文件选择直接执行在 P4V 中显示"?
宏
我现在有一个很好的解决方案.只处理宏事件 SolutionItemsEvents_ItemRenamed.
这是通过单击工具->宏->宏IDE打开宏IDE来完成的.然后将以下事件处理程序添加到您的宏项目:
Private Sub SolutionItemsEvents_ItemRenamed(ByVal ProjectItem As EnvDTE.ProjectItem,ByVal OldName As String)处理 SolutionItemsEvents.ItemRenamedDim 进程作为 System.Diagnostics.Processprocess.Start("p4", "move -k" & ProjectItem.Properties.Parent.Document.Path &\" &旧名 &" " &项目项.文档.路径)结束子
看截图:
如您所见,它只是调用了p4 move -k".需要-k"选项,因为在重命名后旧文件已经被删除,所以 Perforce 会在没有-k"的情况下抛出错误.-k"使 Perforce 仅重命名服务器上的文件.
如果您收到 Perforce 连接错误,您需要添加一个 P4CONFIG 文件来定义连接.这是由:
将文件 p4config.txt 添加到项目目录(或其任何父目录),内容为:
P4CLIENT=您的工作空间
P4USER=用户
P4PORT=p4server:1234设置环境变量 P4CONFIG=p4config.txt
现在您可以通过任何方式更改文件(解决方案资源管理器项->重命名、解决方案资源管理器项->F2、ReSharper 的重命名文件以匹配类型名称、ReSharper 的类重命名em> (Ctrl+R,R),...).
但请记住:如果我尝试在一次签入中编辑和重命名同一个文件,并且如果我在另一个人签出同一个文件时重命名一个文件,我会遇到问题.>
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:
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.
这篇关于如何在使用 Perforce 在 Visual Studio 中重命名文件时保留更改历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!