获取最新签入号(最新变更集id)

发布于 2025-01-04 22:02:41 字数 353 浏览 4 评论 0原文

有没有办法以编程方式获取最新的变更集版本。

获取特定文件的变更集 ID 相当容易:

var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://my.tfs.com/DefaultCollection"));
        tfs.EnsureAuthenticated();
        var vcs = tfs.GetService<VersionControlServer>();

然后调用 GetItems 或 QueryHistory,但我想知道最后一次签入号码是什么。

Is there a way to get programmatically latest changeset version in general.

It's fairly easy to get changeset id for certain file :

var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://my.tfs.com/DefaultCollection"));
        tfs.EnsureAuthenticated();
        var vcs = tfs.GetService<VersionControlServer>();

and then call GetItems or QueryHistory, but i would like to know what was the last checkin number.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

揪着可爱 2025-01-11 22:02:41

你可以这样做:

var latestChangesetId =
    vcs.QueryHistory(
        "$/",
        VersionSpec.Latest,
        0,
        RecursionType.Full,
        String.Empty,
        VersionSpec.Latest,
        VersionSpec.Latest,
        1,
        false,
        true)
        .Cast<Changeset>()
        .Single()
        .ChangesetId;

You can do it like this:

var latestChangesetId =
    vcs.QueryHistory(
        "$/",
        VersionSpec.Latest,
        0,
        RecursionType.Full,
        String.Empty,
        VersionSpec.Latest,
        VersionSpec.Latest,
        1,
        false,
        true)
        .Cast<Changeset>()
        .Single()
        .ChangesetId;
玻璃人 2025-01-11 22:02:41

使用 VersionControlServer.GetLatestChangesetId 获取最新的变更集 ID,如用户 tbaskan 在评论中提到的。

(在 TFS Java SDK 中为 VersionControlClient.getLatestChangesetId

Use VersionControlServer.GetLatestChangesetId to get the latest changeset id, as mentioned by user tbaskan in the comments.

(In the TFS Java SDK it's VersionControlClient.getLatestChangesetId)

可可 2025-01-11 22:02:41

我在执行后使用以下 tf 命令来执行此

    /// <summary>
    /// Return last check-in History of a file
    /// </summary>
    /// <param name="filename">filename for which history is required</param>
    /// <returns>TFS history command</returns>
    private string GetTfsHistoryCommand(string filename)
    {
        //tfs history command (return only one recent record stopafter:1)
        return string.Format("history /stopafter:1 {0} /noprompt", filename);    // return recent one row
    }

操作我解析该命令的输出以获取变更集编号

    using (StreamReader Output = ExecuteTfsCommand(GetTfsHistoryCommand(fullFilePath)))
        {
            string line;
            bool foundChangeSetLine = false;
            Int64 latestChangeSet;
            while ((line = Output.ReadLine()) != null)
            {
                if (foundChangeSetLine)
                {
                    if (Int64.TryParse(line.Split(' ').First().ToString(), out latestChangeSet))
                    {
                        return latestChangeSet;   // this is the lastest changeset number of input file
                    }
                }
                if (line.Contains("-----"))       // output stream contains history records after "------" row
                    foundChangeSetLine = true;
            }
        }

这是我执行命令的方式

    /// <summary>
    /// Executes TFS commands by setting up TFS environment
    /// </summary>
    /// <param name="commands">TFS commands to be executed in sequence</param>
    /// <returns>Output stream for the commands</returns>
    private StreamReader ExecuteTfsCommand(string command)
    {
        logger.Info(string.Format("\n Executing TFS command: {0}",command));
        Process process = new Process();
        process.StartInfo.CreateNoWindow = true;
        process.StartInfo.FileName = _tFPath;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardInput = true;
        process.StartInfo.Arguments = command;
        process.StartInfo.RedirectStandardError = true;
        process.Start();
        process.WaitForExit();                                               // wait until process finishes   
        // log the error if there's any
        StreamReader errorReader = process.StandardError;
        if(errorReader.ReadToEnd()!="")
            logger.Error(string.Format(" \n Error in TF process execution ", errorReader.ReadToEnd()));
        return process.StandardOutput;
    }

不是一种有效的方法,但仍然是在 TFS 2008 中有效的解决方案,希望这会有所帮助。

I use following tf command for this

    /// <summary>
    /// Return last check-in History of a file
    /// </summary>
    /// <param name="filename">filename for which history is required</param>
    /// <returns>TFS history command</returns>
    private string GetTfsHistoryCommand(string filename)
    {
        //tfs history command (return only one recent record stopafter:1)
        return string.Format("history /stopafter:1 {0} /noprompt", filename);    // return recent one row
    }

after execution I parse the output of this command to get changeset number

    using (StreamReader Output = ExecuteTfsCommand(GetTfsHistoryCommand(fullFilePath)))
        {
            string line;
            bool foundChangeSetLine = false;
            Int64 latestChangeSet;
            while ((line = Output.ReadLine()) != null)
            {
                if (foundChangeSetLine)
                {
                    if (Int64.TryParse(line.Split(' ').First().ToString(), out latestChangeSet))
                    {
                        return latestChangeSet;   // this is the lastest changeset number of input file
                    }
                }
                if (line.Contains("-----"))       // output stream contains history records after "------" row
                    foundChangeSetLine = true;
            }
        }

This how I execute the command

    /// <summary>
    /// Executes TFS commands by setting up TFS environment
    /// </summary>
    /// <param name="commands">TFS commands to be executed in sequence</param>
    /// <returns>Output stream for the commands</returns>
    private StreamReader ExecuteTfsCommand(string command)
    {
        logger.Info(string.Format("\n Executing TFS command: {0}",command));
        Process process = new Process();
        process.StartInfo.CreateNoWindow = true;
        process.StartInfo.FileName = _tFPath;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardInput = true;
        process.StartInfo.Arguments = command;
        process.StartInfo.RedirectStandardError = true;
        process.Start();
        process.WaitForExit();                                               // wait until process finishes   
        // log the error if there's any
        StreamReader errorReader = process.StandardError;
        if(errorReader.ReadToEnd()!="")
            logger.Error(string.Format(" \n Error in TF process execution ", errorReader.ReadToEnd()));
        return process.StandardOutput;
    }

Not a efficient way but still a solution this works in TFS 2008, hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文