TFS2010-错误的变更集出现在SourceGetVersion [英] TFS2010 - Wrong changeset appearing at SourceGetVersion

查看:59
本文介绍了TFS2010-错误的变更集出现在SourceGetVersion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在安装Team Foundation Server 2010,并且在执行构建时发现一个非常奇怪的行为:

I am currently setting up a Team Foundation Server 2010 and I found a very strange behavior when performing a build:

情况已说明:
2个分支

The situation explained: We have 2 Branches


  • 发展

  • Main

所有开发人员仅将代码检入Development分支。每天一次,构建管理器将一些变更集合并到Main分支中。在开发分支上,每个签入都在运行连续构建。在Main分支上,每天(夜晚)一次触发构建。

All developers check in code into the Development branch only. Once per day, the build manager merges some changesets over to the Main branch. On the Development brach, a continuous build at each check in is running. On the Main branch, once per day (in the night) a build is triggered.

现在,假设变更集1-100在下午5点被合并到主分支中,将变更集101作为合并操作。一些开发人员在5点进入开发分支后,签入变更集102-106。现在在晚上11点,每日构建会自动触发并在Main分支上运行。 Main分支的最后一个变更集是变更集101。但是,构建详细信息显示了变更集106:

Now suppose that the changesets 1-100 are being merged into the Main brach at 5pm, giving changeset 101 as the merge operation. Some developers check in changesets 102-106 after 5 o'clock into the Development branch. Now at 11pm the daily build is automatically triggered and runs on the Main branch. The last changeset of the Main branch is changeset 101. However, the Build details shows changeset 106:

我可以想象这种行为是故意的,因为如果您在Main分支上签出变更集106 ,实际上您将获得变更集101的内容。但是,如果此构建摘要显示正确的数字,它将更具可读性。

I could imagine that this behavior is intended, because if you check out changeset 106 on the Main branch, you will in fact get the content of changeset 101. But it would be much more readable if this Build summary showed the correct number.

问题1:有没有办法SourceGetVersion信息输出的过程?

Question 1: Is there a way of manipulating the ouput of the SourceGetVersion information? Maybe through the Build Process Template?

在第二种情况下,TFS表现得更奇怪:
在排队新的构建时,可以选择输入获取版本参数,如下图所示:

The second scenario, where the TFS behaves strange is even worse: When queuing a new build, there is the option of entering the "Get Version" Parameter, as shown in the following picture:

如果我现在单击队列,则将触发构建,并且再次构建细节将输出变更集106,尽管我专门将其设置为更改集76。

If I now click on "queue", the build is triggered and AGAIN the build detail outputs the changeset 106 although I specifically set it to get changeset 76.

问题2:这是一个错误吗?是否有修复程序或解决此问题的方法?还是必须设置任何选项标志?

Question 2: Is this a bug? Is there a hotfix or something to fix this? Or is there any option flag that has to be set?

我希望有人对此有所了解。我真的不相信这是一个错误,因为它是至关重要的功能,因此其他人之前必须已经遇到过。

I hope someone knows more about this. I don't really believe that this is a bug, because it is such a vital functionality that other people must have encountered it before.

感谢您的帮助!
Christian

Thanks for any help!! Christian

编辑1

团队的文件夹结构项目是:

The folder structure of the Team Project is:

$ ProjectName

$ProjectName


  • BuildProcessTemplates

  • 文档

  • SourceCode


    • 开发<-这是一个分支


      • 第三方

      • 来源

      • BuildProcessTemplates
      • Documentation
      • SourceCode
        • Development <-- this is a branch
          • 3rdParty
          • Source

          • 3rdParty


          该构建只会拉出Main分支及其下面的所有内容。

          The build only pulls the Main branch and everything below it.

          编辑2

          以下是构建定义中Workspace选项卡的图片:

          Here is a picture of the Workspace tab in the build definition:

          推荐答案

          最后我了解了发生的情况:

          Finally I found out what is going on:

          基本在我的图片1中可以看到的变更集始终是最新的整个 Team Project Collection 的变更集。它是类型为 IBuildDetails的对象 BuildDetails上的属性 SourceGetVersion。

          Basically The changeset that can be seen in my picture 1 is always the latest changeset of the entire Team Project Collection. It is the property "SourceGetVersion" on the object "BuildDetails" of type "IBuildDetails".

          我认为这是一个可以解决的错误:
          如果将BuildDetails.SourceGetVersion(它是一个字符串)更改为其他值,则构建摘要将显示更新的字符串。此外,然后将其正确保存到集合数据库中。

          I think this is a bug which can be worked around: If you change the BuildDetails.SourceGetVersion (which is a string) to some other value, then the build summary will show the updated string. Furthermore, it is then saved correctly to the collection database.

          为了添加正确的变更集编号,我要做的是创建了一个自定义生成活动,该活动将应该作为输入参数构建的分支。它输出正确的变更集。该活动通过连接到TFS并下载历史记录来查找正确的变更集。然后,它查看历史记录中的所有项目,并输出最大的变更集编号。这是该活动的代码:

          What I have done in order to add the correct changeset number is I have created a custom build activity that takes the branch which should be build as input parameter. It outputs the correct changeset. The activity finds out the correct changeset by connecting to the TFS and downloading the History. Then it looks at all the items in the history and outputs the largest changeset number. Here is the code of that activity:

          using System.Activities;
          using System.Collections;
          using System.Net;
          using Microsoft.TeamFoundation.Client;
          using Microsoft.TeamFoundation.VersionControl.Client;
          using Microsoft.TeamFoundation.Build.Client;
          
          namespace SourceGetVersionActivity
          {
              [BuildActivity(HostEnvironmentOption.All)]
              public sealed class SourceGetVersionActivity : CodeActivity<string>
              {
                  // Define an activity input argument of type string
                  public InArgument<string> Branch { get; set; }
          
                  // If your activity returns a value, derive from CodeActivity<TResult>
                  // and return the value from the Execute method.
                  protected override string Execute(CodeActivityContext context)
                  {
                      // Obtain the runtime value of the Text input argument
                      string branch = context.GetValue(this.Branch);
          
                      ICredentials account = new NetworkCredential("Useranme", "password", "domain");
          
                      // connect / authenticate with tfs
                      TeamFoundationServer tfs = new TeamFoundationServer("http://tfs:8080/tfs/CollectionName", account);
                      tfs.Authenticate();
          
                      // get the version control service
                      VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
          
                      IEnumerable changesets = versionControl.QueryHistory(branch, VersionSpec.Latest, 0, RecursionType.Full,
                          null, null, null, int.MaxValue, false, false, false, false);
          
                      int maxVersion = 0;
          
                      foreach (Changeset c in changesets)
                      {
                          if (c.ChangesetId > maxVersion)
                          {
                              maxVersion = c.ChangesetId;
                          }
                      }
          
                      return string.Concat('C', maxVersion.ToString());
                  }
              }
          }
          

          我很快将此活动称为

          基本上在BuildProcessTemplate中,我添加了一个参数(字符串) Branch,该字符串需要填充一个指向以下内容的字符串:正在构建的顶层文件夹。自定义活动将其作为输入并输出一个字符串,该字符串是正确的变更集ID。 BuildDetail.SourceGetVersion属性将被正确的变更集ID覆盖。

          Basically in the BuildProcessTemplate I have added an Argument (string) "Branch" which needs to be filled with a string that points to the top folder that is being build. The custom activity takes that as input and outputs a string which is the correct changeset id. The BuildDetail.SourceGetVersion property will then be overriden by the correct changeset id.

          我真的很奇怪,似乎没有其他人遇到过这个问题。我在互联网上找不到同样问题的人。无论如何,我希望这个答案将来也会对其他人有所帮助。

          I find it really strange that no-one else seems to have encountered this problem. I could not find any person on the internet with the same problem. Anyway, I hope this answer helps someone else in the future as well.

          编辑-直接在Workflow Foundation中编写以上代码:

          要使用更紧凑的代码来获得正确的变更集并避免自定义活动,也可以直接使用Workflow Foundation。下面是代码(完全按照上面的C#代码完成):

          To get the correct changeset using more compact code and avoiding custom activites, it is also possible to use Workflow Foundation directly. Below is the "code" (doing exactly what is done in above C# code):

          (1)GetTeamProjectCollection活动获取当前集合。我将其保存在 TeamProjectCollection 变量中(请参见图片底部)。重要说明:该变量需要在此序列内定义,如果在外部范围内定义该变量,则会发生错误:无法序列化类型'Microsoft.TeamFoundation.Client.TfsTeamProjectCollection'。请确认该类型为public,并且其中一个具有默认构造函数或实例描述符。

          (1) The GetTeamProjectCollection activity gets the current collection. I am saving it inside the TeamProjectCollection variable (see bottom of the picture). Important: The variable needs to be defined inside this sequence, if you define it in outer scope, an error will occur: "Unable to serialize type 'Microsoft.TeamFoundation.Client.TfsTeamProjectCollection'. Verify that the type is public and either has a default constructor or an instance descriptor."

          (2)在 TeamProjectCollection.GetService(Of VersionControlServer).QueryHistory(Branch,VersionSpec.Latest,0, RecursionType.Full,Nothing,Nothing,Nothing,Integer.MaxValue,False,False,False).Cast(Of Changeset)()
          Foreach循环的TypeArgument是 Microsoft.TeamFoundation.VersionControl.Client.Changeset 。
          此表达式从集合中获取版本控制对象,将其称为 QueryHistory方法,该方法返回带有所有变更集的IEnumerable。

          (2) Foreach "changeset" in "TeamProjectCollection.GetService(Of VersionControlServer).QueryHistory(Branch, VersionSpec.Latest, 0, RecursionType.Full, Nothing, Nothing, Nothing, Integer.MaxValue, False, False, False).Cast(Of Changeset)()" The TypeArgument of the Foreach loop is "Microsoft.TeamFoundation.VersionControl.Client.Changeset". This expression gets the version control object from the collection, calls it "QueryHistory" method which returns an IEnumerable with all changesets.

          (3)遍历所有变更集并查看ChangesetId。然后将最大ChangesetId保存到变量 maxId。

          (3) So we are iterating over all changesets and looking at the ChangesetId. Then saving the maximum ChangesetId to the variable "maxId".

          (4)最后,BuildDetails.SourceGetVersion = C + maxId.ToString()。

          (4) At the end, BuildDetails.SourceGetVersion = "C" + maxId.ToString(). The "C" indicates, that the version is a changeset.

          我希望有人觉得这段代码有用!

          I hope someone finds this piece of "Code" useful!

          基督徒

          这篇关于TFS2010-错误的变更集出现在SourceGetVersion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆