visual-studio Visual Studio 的源代码控制集成如何与 Perforce 配合使用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/261525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 09:52:08  来源:igfitidea点击:

How does Visual Studio's source control integration work with Perforce?

visual-studioversion-controlperforce

提问by Weeble

We're using Perforce and Visual Studio. Whenever we create a branch, some projects will not be bound to source control unless we use "Open from Source Control", but other projects work regardless. From my investigations, I know some of the things involved:

我们正在使用 Perforce 和 Visual Studio。每当我们创建一个分支时,除非我们使用“从源代码管理打开”,否则某些项目将不会被绑定到源代码管理,但其他项目无论如何都可以工作。通过我的调查,我知道其中涉及的一些事情:

In our .csproj files, there are these settings:

在我们的 .csproj 文件中,有以下设置:

  • <SccProjectName>
  • <SccLocalPath>
  • <SccAuxPath>
  • <SccProvider>
  • <Scc 项目名称>
  • <SccLocalPath>
  • <SccAuxPath>
  • <SccProvider>

Sometimes they are all set to "SAK", sometimes not. It seems things are more likely to work if these say "SAK".

有时它们都设置为“SAK”,有时则不是。如果这些说“SAK”,事情似乎更有可能奏效。

In our .sln file, there are settings for many of the projects:

在我们的 .sln 文件中,有许多项目的设置:

  • SccLocalPath#
  • SccProjectFilePathRelativizedFromConnection#
  • SccProjectUniqueName#
  • SccLocalPath#
  • SccProjectFilePathRelativizedFromConnection#
  • SccProjectUniqueName#

(The # is a number that identifies each project.) SccLocalPath is a path relative to the solution file. Often it is ".", sometimes it is the folder that the project is in, and sometimes it is ".." or "..\..", and it seems to be bad for it to point to a folder above the solution folder. The relativized one is a path fromthat folder to the project file. It will be missing entirely if SccLocalPath points to the project's folder. If the SccLocalPath has ".." in it, this path might include folder names that are not the same between branches, which I think causes problems.

(# 是标识每个项目的数字。) SccLocalPath 是相对于解决方案文件的路径。经常是“.”,有时是项目所在的文件夹,有时是“..”或“..\..”,指向上面的文件夹好像不好解决方案文件夹。相对化的是该文件夹到项目文件的路径。如果 SccLocalPath 指向项目的文件夹,它将完全丢失。如果 SccLocalPath 中有“..”,则此路径可能包含分支之间不相同的文件夹名称,我认为这会导致问题。

So, to finally get to the specifics I'd like to know:

所以,为了最终了解我想知道的细节:

  • What happens when you do "Change source control" and bind projects? How does Visual Studio decide what to put in the project and solution files?
  • What happens when you do "Open from source control"?
  • What's this "connection" folder that SccLocalPath and SccProjectFilePathRelativizedFromConnection refer to? How does Visual Studio/Perforce pick it?
  • Is there some recommended way to make the source control bindings continue to work even when you create a new branch of the solution?
  • 当您执行“更改源代码控制”并绑定项目时会发生什么?Visual Studio 如何决定将什么放入项目和解决方案文件中?
  • 当您执行“从源代码管理打开”时会发生什么?
  • SccLocalPath 和 SccProjectFilePathRelativizedFromConnection 所指的这个“连接”文件夹是什么?Visual Studio/Perforce 如何选择它?
  • 即使创建解决方案的新分支,是否有一些推荐的方法可以使源代码控制绑定继续工作?


Added June 2012:I don't use Perforce any more, so I can't vouch for it, but have a look at KCD's answerbelow. Apparently there's a new P4 VS pluginunder development. Hopefully it should clear up all this mess!

2012 年 6 月添加:我不再使用 Perforce,所以我不能保证它,但看看下面KCD 的回答。显然有一个新的 P4 VS 插件正在开发中。希望它应该清除所有这些混乱!

回答by Milan Gardian

Introduction

介绍

I would disagree with the claim that Perforce integration in Visual Studio is "terrible". Rather, I'd define it as "out of the box experience is less than optimal" :-). The following sections discuss my understanding of the integration and recommendations for project/solution setup.

我不同意 Visual Studio 中的 Perforce 集成“可怕”的说法。相反,我将其定义为“开箱即用的体验不是最佳的”:-)。以下部分讨论了我对项目/解决方案设置的集成和建议的理解。

If you're not interested in the details of how the source control integration works you can skip to the end of this answer where I summarize answers to Weeble's question.

如果您对源代码控制集成如何工作的细节不感兴趣,可以跳到本答案的末尾,我总结了 Weeble 问题的答案。

Disclaimer: The following sections are just educated guesses based on my empirical experience, however I've used the technique over many years in many projects (each project having multiple experimental/trunk/maintenance/release branches, sometimes even multiple solution files, without issues). The disadvantage is that you have to manuallyupdate the project files - but the 2 minute investment is amortized over the lifetime of a project pretty nicely IMHO :-).

免责声明:以下部分只是基于我的经验经验的有根据的猜测,但是我已经在许多项目中使用该技术多年(每个项目都有多个实验/主干/维护/发布分支​​,有时甚至多个解决方案文件,没有问题)。缺点是您必须手动更新项目文件 - 但 2 分钟的投资在项目的整个生命周期内很好地摊销,恕我直言:-)。

Solution vs. Project

解决方案与项目

Visual Studio uses source control binding information from both solution file and each project file during the initial solution loading. This binding information is then stored in name.suofile (assuming we're using name.slnas solution) - note that suofiles are marked with hiddenflag so they won't be visible in file explorer (unless you override the "Hidden files and folders" option).

Visual Studio 在初始解决方案加载期间使用来自解决方案文件和每个项目文件的源代码管理绑定信息。然后将此绑定信息存储在name.suo文件中(假设我们使用name.sln作为解决方案) - 请注意,suo文件标有隐藏标志,因此它们在文件资源管理器中不可见(除非您覆盖“隐藏文件和文件夹”选项)。

The easiest way to re-bind to source control provider if anything goes wrong is to delete the appropriate suofile and reopen solution. After suo file has been created, changes to <Scc*> elements have no effect.

如果出现任何问题,重新绑定到源代码控制提供程序的最简单方法是删除相应的suo文件并重新打开解决方案。创建 suo 文件后,对 <Scc*> ​​元素的更改无效。

If during the initial solution opening there is a discrepancy between the binding information stored in solution file and information stored in project file, Visual Studio will attempt to fix this (sometimes it will even prompt for your decision to choose whether the information in solution or the information in project should be used as a "master" to resolve the discrepancy):

如果在初始解决方案打开期间,解决方案文件中存储的绑定信息与项目文件中存储的信息存在差异,Visual Studio 将尝试修复此问题(有时它甚至会提示您决定选择解决方案中的信息还是项目文件中的信息)项目中的信息应作为解决差异的“主”):

alt text

替代文字

Why is Visual Studio violating DRY (Don't Repeat Yourself) principle? I have no idea. I presume this has historic reasons and is tightly coupled to the needs of that nightmare called Visual Source Safe :-).

为什么 Visual Studio 违反了 DRY(不要重复自己)原则?我不知道。我认为这有历史原因,并且与称为 Visual Source Safe :-) 的噩梦的需求紧密相关。

How to set it up "correctly"?

如何“正确”设置它?

When adding either new or existing solutions/projects to Perforce, I alwaysstart by creating a blank solution (see the "Source-controlling a blank solution" section). I then add projects to this blank solution, one after another. The steps differ slightly based on whether the project being added already exists (see the "Source-controlling existing (unbound) projects" and "Source-controlling existing (bound) projects" sections) or I need to create a new one (see the "Source-controlling new projects" section).

在向 Perforce 添加新的或现有的解决方案/项目时,我总是从创建一个空白解决方案开始(请参阅“源控制空白解决方案”部分)。然后我将项目一个接一个地添加到这个空白解决方案中。根据要添加的项目是否已经存在(请参阅“源代码控制现有(未绑定)项目”和“源代码控制现有(绑定)项目”部分)或我需要创建一个新项目(请参阅“源代码控制新项目”部分)。

Source-controlling a blank solution

源代码控制空白解决方案

To add a new blank solution to source control, do the following:

要将新的空白解决方案添加到源代码管理,请执行以下操作:

  1. Start Visual Studio, "New" -> "Project..." -> "Other project types" -> "Blank solution"; fill in solution name and location, "OK" button
  2. "File" -> "Source Control" -> "Add Solution to Source Control..."
  3. In the connection dialog enter appropriate P4 server port, client and user (note that view of the selected client must include the location that you picked in step 1)
  4. "View" -> "Pending Checkins" -> "Check In" -> in the submit dialog instead of hitting the "Submit" button, use "Cancel".
    Reason: The "Check In" action will create a new file, "name.vssscc", then add both "name.sln" and "name.vssscc" to Perforce's default changelist; by cancelling the submit dialog we will keep the "add" operation pending and will be able to edit the files before submitting to P4
  5. Close Visual Studio
  6. Open the name.sln file in your favourite editor (notepad, if you're really desperate :-) ) and add two new lines (SccProjectName0and SccProvider0) - the blank solution file should now have a source control section as follows:

    GlobalSection(SourceCodeControl) = preSolution
        SccNumberOfProjects = 1
        SccLocalPath0 = .
        SccProjectName0 = Tutorial
        SccProvider0 = MSSCCI:Perforce\u0020SCM
    EndGlobalSection
    

    The values should be chosen as follows:

    • SccProjectName0: an arbitrary string that will be displayed in "Change Source Control" dialog as "Server Binding". This name is used to determine what projects/solution files can share the same source control connection. I recommend not using space for this name as escaping rules for spaces are different in solution and project files.
    • SccProvider0: hard-coded value "MSSCCI:Perforce\u0020SCM".
  7. Submit the two pending files using the Perforce client of your choice (p4.exe, P4Win, P4V)
  1. 启动Visual Studio,“新建”->“项目...”->“其他项目类型”->“空白解决方案”;填写解决方案名称和位置,“确定”按钮
  2. “文件”->“源代码管理”->“将解决方案添加到源代码管理...”
  3. 在连接对话框中输入适当的 P4 服务器端口、客户端和用户(注意所选客户端的视图必须包括您在步骤 1 中选择的位置)
  4. “查看”->“挂起签入”->“签入”-> 在提交对话框中而不是点击“提交”按钮,使用“取消”。
    原因:“签入”操作将创建一个新文件“name.vssscc”,然后将“name.sln”和“name.vssscc”添加到 Perforce 的默认更改列表中;通过取消提交对话框,我们将保持“添加”操作挂起,并且能够在提交到 P4 之前编辑文件
  5. 关闭 Visual Studio
  6. 在你最喜欢的编辑器(记事本,如果你真的很绝望:-))中打开 name.sln 文件并添加两个新行(SccProjectName0SccProvider0) - 空白的解决方案文件现在应该有一个源代码控制部分,如下所示:

    GlobalSection(SourceCodeControl) = preSolution
        SccNumberOfProjects = 1
        SccLocalPath0 = .
        SccProjectName0 = Tutorial
        SccProvider0 = MSSCCI:Perforce\u0020SCM
    EndGlobalSection
    

    应按如下方式选择值:

    • SccProjectName0:将在“更改源代码管理”对话框中显示为“服务器绑定”的任意字符串。此名称用于确定哪些项目/解决方案文件可以共享相同的源代码控制连接。我建议不要为此名称使用空格,因为空格的转义规则在解决方案和项目文件中是不同的。
    • SccProvider0:硬编码值“MSSCCI:Perforce\u0020SCM”。
  7. 使用您选择的 Perforce 客户端(p4.exe、P4Win、P4V)提交两个待处理文件

You can now test the bindings:

您现在可以测试绑定:

  1. Make sure Visual Studio is closed
  2. Delete **all* files except the name.sln (especially the name.suo)
  3. Open Visual Studio and use it to open name.sln
  4. A connection dialog should appear, use appropriate port/client/user and click OK
  5. Solution explorer should now display the solution node with a padlock overlay icon: Source-controlled blank solution
  6. You can now verify source control status of the solution by using "File" -> "Source Control" -> "Change Source Control...": Source control status of blank solutionNote: The column "Server Binding" is showing the value we chose for "SccProjectName0".
  1. 确保 Visual Studio 已关闭
  2. 删除除name.sln(尤其是name.suo)之外的**所有*文件
  3. 打开 Visual Studio 并使用它打开 name.sln
  4. 应出现一个连接对话框,使用适当的端口/客户端/用户,然后单击确定
  5. 解决方案资源管理器现在应该显示带有挂锁覆盖图标的解决方案节点: 源控空白解决方案
  6. 您现在可以使用“文件”->“源代码管理”->“更改源代码管理...”来验证解决方案的源代码管理状态: 空白溶液的源头控制状态注意:“服务器绑定”列显示我们为“SccProjectName0”选择的值.

Source-controlling new projects

源代码控制新项目

If you're creating a brand-new project and would like to immediately start tracking it in a Perforce depot, follow these steps:

如果您正在创建一个全新的项目并希望立即开始在 Perforce 仓库中对其进行跟踪,请按照以下步骤操作:

  1. Open the source-controlled solution in Visual Studio
  2. "File" -> "Add" -> "New Project..." - pick the project type you're adding, name and location (location should be a subdirectory of the directory where the solution file is stored)
  3. "File" -> "Save All" (this will commit all in-memory changes to solution file and the newly created project file to the disk)
  4. Manually edit the project file you just created using an editor of your choice (come on, notepad AGAIN? ;-) ). Add the following property elements into a PropertyGroup (any property group):

    <PropertyGroup>
        ...
        <SccProjectName>Tutorial</SccProjectName>
        <SccLocalPath>..\..</SccLocalPath>
        <SccProvider>MSSCCI:Perforce SCM</SccProvider>
        ...
    </PropertyGroup>
    

    The values should be chosen as follows:

    • SccProjectName- this is the value that is displayed in "Change Source Control" dialog as "Server Binding"; should be the same as the value you used for SccProjectName0 in blank solution; if not the same, solution and this project won't be able to share the same source control provider connection
    • SccLocalPath- relative path to the reference directory (displayed in "Change Source Control" dialog as "Local binding"); because I recommend using the solution directory as the reference directory, this is in effect relative path from directory containing project file to directory containing solution file (my example is storing projects in "(solutionDir)/Source/ProjectName/projectName.csproj", thus the relative path is "two levels up")
    • SccProvider- hard-coded value "MSSCCI:Perforce SCM"; this is used to determine what SCCAPI provider are the Scc* binding values valid for
  5. Switch back to Visual Studio; it should automatically detect that the project file has been updated externally and offer to reload it (if not, unload and reload the project manually)

  6. "View" -> "Pending Checkins"
  7. "Check In" -> I recommend right-clicking on (solutionName).vssscc file and selecting "Revert if unchanged" (even though Visual Studio opens it for edit, it remains unchanged); provide description and submit the change
  1. 在 Visual Studio 中打开源代码控制的解决方案
  2. “文件” -> “添加” -> “新建项目...” - 选择您要添加的项目类型、名称和位置(位置应该是存储解决方案文件的目录的子目录)
  3. “文件”->“全部保存”(这会将所有内存中的更改提交到解决方案文件和新创建的项目文件到磁盘)
  4. 使用您选择的编辑器手动编辑您刚刚创建的项目文件(来吧,再次记事本?;-))。将以下属性元素添加到 PropertyGroup(任何属性组)中:

    <PropertyGroup>
        ...
        <SccProjectName>Tutorial</SccProjectName>
        <SccLocalPath>..\..</SccLocalPath>
        <SccProvider>MSSCCI:Perforce SCM</SccProvider>
        ...
    </PropertyGroup>
    

    应按如下方式选择值:

    • SccProjectName- 这是在“更改源代码管理”对话框中显示为“服务器绑定”的值;应该与您在空白解决方案中用于 SccProjectName0 的值相同;如果不一样,解决方案和这个项目将无法共享相同的源控制提供程序连接
    • SccLocalPath- 引用目录的相对路径(在“更改源代码管理”对话框中显示为“本地绑定”);因为我建议使用解决方案目录作为参考目录,这实际上是从包含项目文件的目录到包含解决方案文件的目录的相对路径(我的示例是将项目存储在“(solutionDir)/Source/ProjectName/projectName.csproj”中,因此相对路径是“两个级别”)
    • SccProvider- 硬编码值“MSSCCI:Perforce SCM”;这用于确定哪些 SCCAPI 提供程序是有效的 Scc* 绑定值
  5. 切换回 Visual Studio;它应该自动检测到项目文件已在外部更新并提供重新加载它(如果没有,请手动卸载并重新加载项目)

  6. “查看”->“待签到”
  7. “签入”-> 我建议右键单击 (solutionName).vssscc 文件并选择“如果未更改则还原”(即使 Visual Studio 打开它进行编辑,它也保持不变);提供描述并提交更改

To verify that the newly added project is bound properly, you can follow these steps:

验证新添加的项目是否绑定正确,可以按照以下步骤操作:

  1. Make sure Visual Studio is closed
  2. Delete (solutionName).suo file as well as MSSCCPRJ.SCC (in solution directory)
  3. Open Visual Studio and use it to open (solutionName).sln
  4. A connection dialog should appear, use appropriate port/client/user and click OK
  5. Solution explorer should now display the project node with a padlock overlay icon: Source-controlled projects
  6. You can now verify source control status of the solution by using "File" -> "Source Control" -> "Change Source Control...": Status of source-controlled projects

    One thing to note about this status screenshot is that when I selected the solution row, all the remaining rows were "selected" as well (blue highlight). This is because all those entries have the same "Server Binding" + "Local Binding" and thus share the same source-control-provider (P4) connection.

    Also note that "Relative Path" for both projects has two levels, and are relative to the same "Local Binding" - the directory where solution file resides.

  1. 确保 Visual Studio 已关闭
  2. 删除 (solutionName).suo 文件以及 MSSCCPRJ.SCC(在解决方案目录中)
  3. 打开 Visual Studio 并使用它打开 (solutionName).sln
  4. 应出现一个连接对话框,使用适当的端口/客户端/用户,然后单击确定
  5. 解决方案资源管理器现在应该显示带有挂锁覆盖图标的项目节点: 源代码控制项目
  6. 您现在可以使用“文件”->“源代码管理”->“更改源代码管理...”来验证解决方案的源代码管理状态: 源代码控制项目的状态

    关于此状态屏幕截图需要注意的一件事是,当我选择解决方案行时,所有剩余的行也都被“选中”(蓝色突出显示)。这是因为所有这些条目都具有相同的“服务器绑定”+“本地绑定”,因此共享相同的源代码控制提供程序 (P4) 连接。

    另请注意,两个项目的“相对路径”有两个级别,并且相对于相同的“本地绑定” - 解决方案文件所在的目录。

Source-controlling existing (unbound) projects

对现有(未绑定)项目进行源代码控制

If you have existing projects that have not yet been used in any other Perforce solution, follow these steps to add them to Perforce (i.e. importing projects that have not been source-controlled before (Internet downloads etc.) or were using a different source control provider (Visual Source Safe, etc.).

如果您有尚未在任何其他 Perforce 解决方案中使用的现有项目,请按照以下步骤将它们添加到 Perforce(即导入之前未进行源代码控制(Internet 下载等)或正在使用不同源代码控制的项目)提供程序(Visual Source Safe 等)。

  1. Copy the project into appropriate location
  2. Clean-up existing source control bindings (if any):
    • Remove existing project-file bindings, i.e. all properties starting with "Scc"
    • Delete file (projectName).vspscc in the same directory as the project file (if any)
  3. Open the source-controlled solution in Visual Studio
  4. "File" -> "Add" -> "Existing project..." - browse to the project (the copy you created in step 1)
  5. "File" -> "Save All" (this will commit all in-memory changes to solution file)
  6. Follow the steps 4-7 from "Source-controlling new projects" (i.e. you will now add "Scc*" property elements into a PropertyGroup)
  1. 将项目复制到合适的位置
  2. 清理现有的源代码控制绑定(如果有):
    • 删除现有的项目文件绑定,即所有以“Scc”开头的属性
    • 删除与项目文件(如果有)相同目录中的文件(projectName).vspscc
  3. 在 Visual Studio 中打开源代码控制的解决方案
  4. “文件”->“添加”->“现有项目...”-浏览到项目(您在步骤 1 中创建的副本)
  5. “文件”->“全部保存”(这会将所有内存中的更改提交到解决方案文件)
  6. 按照“源代码控制新项目”中的步骤 4-7(即,您现在将“Scc*”属性元素添加到PropertyGroup 中

Verification steps are exactly the same as in "Source-controlling new projects" section.

验证步骤与“源代码控制新项目”部分完全相同。

Source-controlling existing (bound) projects

对现有(绑定)项目进行源代码控制

If you have projects that have already been bound to Perforce using the technique discussed here and you want to use them in a different solution (new branch, alternative solution reusing the project, etc) use the following steps:

如果您的项目已经使用此处讨论的技术绑定到 Perforce,并且您想在不同的解决方案(新分支、重用项目的替代解决方案等)中使用它们,请使用以下步骤:

  1. Integrate the project into desired location
  2. Open the source-controlled solution in Visual Studio
  3. "File" -> "Add" -> "Existing project..." - browse to the project created in step 1 via integration
  4. "View" -> "Pending Checkins" -> "Check In" - add description and submit
  1. 将项目集成到所需位置
  2. 在 Visual Studio 中打开源代码控制的解决方案
  3. “文件”->“添加”->“现有项目...” - 通过集成浏览到在步骤 1 中创建的项目
  4. “查看”->“待签到”->“签入”-添加描述并提交

Summary

概括

  • Source control binding information is stored in both solution and projects, must be in sync (if not, Visual Studio will attempt to fix any discrepancies)
  • I always treat project files as the primary source of binding information and solution files as throwaway files that can be recreated easily by first source-controlling a blank solution and then adding desired projects
  • Solution file should always have valid SccProvider0and SccProjectName0values (have to be added manually with new versions of P4SCC plugins)
  • Project files should always have valid SccProjectName(preferrably same as SccProjectName0), SccLocalPathand SccProvidervalues (also have to be edited manually as the P4SCC defaults are no good)
  • 源代码控制绑定信息存储在解决方案和项目中,必须同步(如果不同步,Visual Studio 将尝试修复任何差异)
  • 我总是将项目文件视为绑定信息的主要来源,将解决方案文件视为一次性文件,通过首先对空白解决方案进行源代码控制,然后添加所需项目,可以轻松重新创建这些文件
  • 解决方案文件应始终具有有效的SccProvider0SccProjectName0值(必须使用新版本的 P4SCC 插件手动添加)
  • 项目文件应始终具有有效的SccProjectName(最好与SccProjectName0相同)、SccLocalPathSccProvider值(也必须手动编辑,因为 P4SCC 默认值不好)

I'm also including answers to your original questions:

我还包括对您原始问题的回答:

What happens when you do "Change source control" and bind projects? How does Visual Studio decide what to put in the project and solution files?

当您执行“更改源代码控制”并绑定项目时会发生什么?Visual Studio 如何决定将什么放入项目和解决方案文件中?

This updates "Scc*" elements in a project file you're rebinding; the solution file is then updated as well so that it is in sync with the project file bindings

这会更新您正在重新绑定的项目文件中的“Scc*”元素;然后解决方案文件也会更新,以便与项目文件绑定同步

What happens when you do "Open from source control"?

当您执行“从源代码管理打开”时会发生什么?

Allows you to pick solution that you'd like to open. Afterwards all the projects included in the solution are automatically synced to head. I find this feature not very useful in Perforce world where you have to create a client anyway and the chances are you're syncing this client from a P4V/P4Win/P4 instead of relying on Visual Studio. This was kind-of useful in Visual Source Safe world where there was no concept of views and you were defining where a repository goes on checkout time.

允许您选择要打开的解决方案。之后,解决方案中包含的所有项目都会自动同步到 head。我发现这个功能在 Perforce 世界中不是很有用,在那里你必须创建一个客户端,而且你很可能从 P4V/P4Win/P4 同步这个客户端,而不是依赖 Visual Studio。这在没有视图概念的 Visual Source Safe 世界中很有用,您正在定义存储库在检出时的位置。

What's this "connection" folder that SccLocalPath and SccProjectFilePathRelativizedFromConnection refer to? How does Visual Studio/Perforce pick it?

SccLocalPath 和 SccProjectFilePathRelativizedFromConnection 所指的这个“连接”文件夹是什么?Visual Studio/Perforce 如何选择它?

This is Visual Studio's bookkeeping. It is determined based on bindings in each project file (I guess in theory if a project file loses binding information for some reason, it could be reconstructed from the solution information...)

这是 Visual Studio 的簿记。它是根据每个项目文件中的绑定确定的(我猜理论上如果项目文件由于某种原因丢失了绑定信息,它可以从解决方案信息中重建......)

Is there some recommended way to make the source control bindings continue to work even when you create a new branch of the solution?

即使创建解决方案的新分支,是否有一些推荐的方法可以使源代码控制绑定继续工作?

I hope the sections above give you some idea of a way that is working very well for me :-).

我希望以上部分能让您了解一种对我来说非常有效的方法:-)。

回答by Timbo

Milan's post is well-researched and well-written, but its length demonstrates beyond a shadow of a doubt that the P4SCC model is broken. Storing source control binding info inside the project & solution files is ridiculous. Enforcing (via sccprojectname) that a project be part of only one solution is equally ridiculous.

Milan 的帖子经过充分研究和编写,但它的长度毫无疑问地表明 P4SCC 模型已被破坏。在项目和解决方案文件中存储源代码控制绑定信息是荒谬的。强制(通过 sccprojectname)一个项目只属于一个解决方案的一部分同样荒谬。

Additionally, P4SCC has a tremendous performance cost in a large solution, as it retrieves info from source control for each file at startup, and maintains that state in memory throughout the development session. It creates extra cruft in the form of information-free .vsscc & vssscc files to support some SCC feature that (AFAICT) Perforce does not use.

此外,P4SCC 在大型解决方案中具有巨大的性能成本,因为它在启动时从每个文件的源代码管理中检索信息,并在整个开发会话期间在内存中维护该状态。它以无信息的 .vsscc 和 vssscc 文件的形式创建额外的内容,以支持 (AFAICT) Perforce 不使用的某些 SCC 功能。

The ideal Perforce integration looks like:

理想的 Perforce 集成如下所示:

  • If I create a new solution, project, or project item, run 'p4 add'.
  • If I change a file, run 'p4 edit'.
  • Some toolbar/context menu integration for revision history, revision graph, timelapse/blame, and 'show in P4 gui'.
  • (nice to have) If I rename a file that exists in the depot, run 'p4 integrate' and 'p4 delete'. If I rename a file opened for add, run 'p4 revert' and 'p4 add'.
  • That's all
  • 如果我创建了一个新的解决方案、项目或项目项,请运行“p4 add”。
  • 如果我更改文件,请运行“p4 edit”。
  • 一些工具栏/上下文菜单集成,用于修订历史、修订图、游戏中时光倒流/责备和“在 P4 gui 中显示”。
  • (很高兴)如果我重命名库中存在的文件,请运行“p4集成”和“p4删除”。如果我重命名为添加而打开的文件,请运行“p4 revert”和“p4 add”。
  • 就这样

We have moved completely away from P4SCC and its bizarre requirements and burdens. Instead we use NiftyPerforce. There are some bugs, but we find working around these bugs to be much less frustrating than working around the design defects in the Perforce<->VSSCC model.

我们已经完全摆脱了 P4SCC 及其奇怪的要求和负担。相反,我们使用NiftyPerforce。存在一些错误,但我们发现解决这些错误比解决 Perforce<->VSSCC 模型中的设计缺陷要少得多。

回答by KCD

Just to keep this current - the P4VS plugin has been rewritten circa 2012

只是为了保持最新状态 - P4VS 插件已在 2012 年左右重写

Now you can perform all of your daily interaction with Perforce naturally, like checking in code and viewing file history, directly from the IDE.

If you're a power user looking for a bit more, P4VS won't disappoint. P4VS is fully compatible with Perforce Streams, and the Stream Graph is accessible from the IDE, along with Time-lapse View and Revision Graph. If you are responsible for branch management, you can merge from P4VS as well.

And, if you work remotely or want to do a little private branching, P4Sandbox can be configured through P4VS.

现在,您可以直接从 IDE 自然地执行与 Perforce 的所有日常交互,例如检入代码和查看文件历史记录。

如果您是一位寻求更多功能的高级用户,P4VS 不会让您失望。P4VS 与 Perforce Streams 完全兼容,并且可以从 IDE 访问 Stream Graph,以及 Time-lapse View 和 Revision Graph。如果你负责分支管理,你也可以从 P4VS 合并。

而且,如果您远程工作或想做一些私有分支,可以通过 P4VS 配置 P4Sandbox。

回答by Zoner

Using Perforce with Visual Studio can be simplified by using the P4CONFIG environment variable.

通过使用 P4CONFIG 环境变量,可以简化 Perforce 与 Visual Studio 的使用。

Basically you go into Visual Studio, Tools -> Options -> Source Control -> Plug-in Settings, Advanced button. This will bring up a Perforce configuration dialog specific to the SCC integration. Switch to the Connection tab, and check the radio button titled 'Bind the workspace that matches your Perforce environment settings'. This will tell perforce to prefer using P4CONFIG environment variable for determining the environment you are under. This same dialog exists in P4V under Edit -> Preferences, but only affects p4v's behavior.

基本上你进入 Visual Studio,工具 -> 选项 -> 源代码管理 -> 插件设置,高级按钮。这将打开一个特定于 SCC 集成的 Perforce 配置对话框。切换到连接选项卡,然后选中标题为“绑定与您的 Perforce 环境设置匹配的工作区”的单选按钮。这将告诉 perforce 更喜欢使用 P4CONFIG 环境变量来确定您所处的环境。这个相同的对话框存在于 P4V 的 Edit -> Preferences 下,但只影响 p4v 的行为。

How you setup the P4CONFIG environment variable is up to you to some degree. I like having them be named the same everywhere so I set a system-wide environment variable P4CONFIG to look for a file named p4config.cfg. This file is just an ini style file, where you can assign other variables such as P4USER, P4CLIENT, P4HOST etc. Perforce will search for this file in the current directory and all parent directories until it encounters one. Basically you put this file in the root most directory of your where your clientspec is mapped to on your hard drive, and leave it alone.

如何设置 P4CONFIG 环境变量在某种程度上取决于您。我喜欢让它们在任何地方都被命名,所以我设置了一个系统范围的环境变量 P4CONFIG 来查找名为 p4config.cfg 的文件。这个文件只是一个 ini 风格的文件,你可以在其中分配其他变量,如 P4USER、P4CLIENT、P4HOST 等。Perforce 将在当前目录和所有父目录中搜索这个文件,直到遇到一个。基本上,您将这个文件放在您的客户端规范映射到您的硬盘驱动器上的最根目录中,并且不管它。

This approach greatly reduces the amount of 'correctness' that the SCC configuration needs in visual studio in order to function. (SAK bindings work fine etc.)

这种方法极大地减少了 Visual Studio 中 SCC 配置需要的“正确性”数量。(SAK 绑定工作正常等)

If after syncing your code from perforce for the first time or to a totaly clean directory structure, and getting a dialog complaining about perforce wanting to either temporarily work offline or remove bindings, there is still some editing you need to do. Primarily the .sln file itself needs to be modified so it knows the sln has SCC bindings for itself . This is done by making sure the following fields are placed right after SccNumberOfProjects in the .sln file.

如果第一次从 perforce 同步您的代码或同步到完全干净的目录结构后,并收到一个对话框,抱怨 perforce 想要暂时离线工作或删除绑定,您仍然需要进行一些编辑。主要是 .sln 文件本身需要修改,以便它知道 sln 具有自己的 SCC 绑定。这是通过确保将以下字段放在 .sln 文件中的 SccNumberOfProjects 之后来实现的。

SccProjectName0 = Perforce\u0020Project
SccProvider0 = MSSCCI:Perforce\u0020SCM

All of the individual projects should work fine with default 'SAK bindings' provided you are using the P4CONFIG approach. Fixing this should allow Perforce to work from a clean sync perfectly, and also eliminate the generation of MSSCCPRJ.SCC cruft in each of the project directories.

如果您使用的是 P4CONFIG 方法,则所有单个项目都应该使用默认的“SAK 绑定”正常工作。解决这个问题应该允许 Perforce 完美地从干净同步开始工作,并且还消除了每个项目目录中 MSSCCPRJ.SCC 残留物的生成。

回答by Ray

Support for renaming a file or moving it to a new folder directory is terribleand painful if using the Visual Studio P4 plug-in integration. No built-in feature exists that alerts P4 to renaming the file or that it has been moved.

如果使用 Visual Studio P4 插件集成,支持重命名文件或将其移动到新文件夹目录是非常糟糕和痛苦的。不存在提醒 P4 重命名文件或文件已被移动的内置功能。

The issue is that renaming a file requires not just updating the associated VS project file but Perforce needs to be informed as well of the change if you want to maintain proper revision history.

问题是重命名文件不仅需要更新关联的 VS 项目文件,而且如果您想保持正确的修订历史记录,还需要将更改通知 Perforce。

Currently, I do not see a way to do both in a single operation if using the VS integration. Instead, you have to:

目前,如果使用 VS 集成,我看不到在单个操作中同时执行这两项操作的方法。相反,您必须:

  1. rename/move the file from within the Perforce client
  2. delete the old filename reference in the project file within VS
  3. add the new filename reference in the project file within VS
  4. submit your changes
  1. 从 Perforce 客户端中重命名/移动文件
  2. 删除 VS 中项目文件中的旧文件名引用
  3. 在 VS 的项目文件中添加新的文件名引用
  4. 提交您的更改

If you use a continuous integration build process and you submit changes at any point prior to the last step, you are guaranteed to have a broken build.

如果您使用持续集成构建过程并在最后一步之前的任何时间提交更改,则可以保证您的构建已损坏。

The problem magnifies significantly the more files that require renaming or moving. This is not a smooth process whatsoever.

需要重命名或移动的文件越多,这个问题就会显着放大。这绝不是一个顺利的过程。

回答by Dave Andersen

After experimenting with Milan Gardian's very informative answer, I think I can provide a simpler solution to get it working pretty well.

在尝试了 Milan Gardian 提供的非常有用的答案之后,我想我可以提供一个更简单的解决方案来让它工作得很好。

As Weeble mentioned, the SAK values work fine when everything else is set up correctly, and they are often the default values (but I think it depends on which project type it is). If they do not show up in your project, just paste in this property group.

正如 Weeble 提到的,当其他一切设置正确时,SAK 值工作正常,并且它们通常是默认值(但我认为这取决于它是哪种项目类型)。如果它们没有出现在您的项目中,只需粘贴到此属性组中即可。

<PropertyGroup>
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>

Add these two lines to the *.sln in the SourceCodeControl GlobalSection. As long as the project files have SAK values, they should inherit the names from the solution.

将这两行添加到 SourceCodeControl GlobalSection 中的 *.sln。只要项目文件具有 SAK 值,它们就应该从解决方案继承名称。

SccProjectName0 = Perforce\u0020Project
SccProvider0 = MSSCCI:Perforce\u0020SCM

No *.vssscc, *.vspscc, or *.SCC files need to be checked in (though they will be generated when the solution is opened).

不需要签入 *.vssscc、*.vspscc 或 *.SCC 文件(尽管它们会在解决方案打开时生成)。

回答by raven

Very poorly. I know that is not the answer to your questions that you were looking for (in the future, perhaps you could narrow the focus?), but source control integration with Visual Studio just sucks. The reason being that they all have to use Microsoft's terrible SCC interface. It's pathetic! They put source control information in the project files! Why would they do that?

很差。我知道这不是您正在寻找的问题的答案(在未来,也许您可​​以缩小重点?),但是与 Visual Studio 的源代码控制集成很糟糕。原因是他们都必须使用微软糟糕的SCC界面。这是可悲的!他们将源代码控制信息放在项目文件中!他们为什么要那样做?

Just abandon the Visual Studio integration and use the Perforce client. It's not that much extra work. You can't spare 30 seconds per day to switch over to the Perforce client and check in/out the files out from there?

只需放弃 Visual Studio 集成并使用 Perforce 客户端即可。没有那么多额外的工作。您不能每天抽出 30 秒切换到 Perforce 客户端并从那里签入/签出文件?

回答by Thomas L Holaday

I can answer the last one.

我可以回答最后一个。

In order to get source control bindings to work even when you create a new branch, follow a strict hierarchical structure:

为了即使在创建新分支时也能使用源代码控制绑定,请遵循严格的层次结构:

/Solution
  /library1
  /library2
  /product1
  /product2
  /subsolution
    /sublibrary1
    /subproduct1

Each file must be in exactly one .vcproj. You can have multiple .vcproj in the same directory, but if they share files, the shared files must go into their own .vcproj.

每个文件都必须在一个 .vcproj 中。您可以在同一目录中拥有多个 .vcproj,但如果它们共享文件,则共享文件必须进入它们自己的 .vcproj。

If you are relentless in this, all the Scc stuff will be relative-path, so a new branch will work (because it only changes the topmost directory).

如果你坚持不懈,所有 Scc 的东西都将是相对路径,所以一个新的分支将起作用(因为它只更改最顶层的目录)。

回答by Mr Twister

This is not a Perforce issue, it is a Visual Studio issue. The ridiculous requirement that source files be modified to allow Visual Studio to understand that there is an SCM tool in use is idiotic.

这不是 Perforce 问题,而是 Visual Studio 问题。修改源文件以允许 Visual Studio 了解正在使用的 SCM 工具的荒谬要求是愚蠢的。

The simple answer is 'stop using the Visual Studio source control integration'. It just plain sucks. Even with TFS it just plain sucks.

简单的答案是“停止使用 Visual Studio 源代码控制集成”。简直糟透了。即使使用 TFS,它也很糟糕。

If you want to be able to check out from within Visual Studio, just create a custom tool. A simple call to 'p4 edit' with the appropriate VS variable is all you need. Want to revert a file? Same idea...call p4 revert with the appropriate variable. Done.

如果您希望能够从 Visual Studio 中签出,只需创建一个自定义工具。您只需要使用适当的 VS 变量简单调用“p4 edit”即可。想要还原文件?同样的想法......使用适当的变量调用 p4 还原。完毕。

Use p4v to manage your source control needs (submissions, history, diffs, etc.) Visual Studio rocks as a source editor. It sucks as an SCM interface.

使用 p4v 来管理您的源代码控制需求(提交、历史记录、差异等)。 Visual Studio 作为源代码编辑器摇摆不定。它作为 SCM 接口很糟糕。