获取TFS把变更的程序集版本 [英] Getting TFS to put the changeset in the assembly version

查看:1278
本文介绍了获取TFS把变更的程序集版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有干净运行的Team Foundation Server生成。它产生几集,我想程序集的版本有最后的数字是的 changset 的数量。也就是说,如果我与例如changeset11667提交组件版本号应为x.y.z.11667。我检查了菱宏,但没有一个是变更集数。

I have got a Team Foundation Server Build running cleanly. It produces several assemblies and I would like the assemblies versions to have the last number to be the changset number. That is, if I commit with a changeset11667 for example the assembly version number should be "x.y.z.11667". I've checked the availible macros, but none is the changeset number.

我仍然希望能够建立我的开发机器正常的在解决方案文件,只是使用的版本号检查。

I would still like to be able to build the solution file on my dev machine as normal, just using the checked in version number.

怎么会去的地方得到这些?

How would I go about getting this in place?

推荐答案

在年底colleagueof雷写道,解决了这个问题下面的MSBuild任务。

In the end a colleagueof mine wrote the following MSBuild task that solved the problem.

public class GetNextBuildNumber : Task
{
    [Required]
    public string TfsCommand { get; set; }

    [Required]
    public string TfsArgument { get; set; }

    [Output]
    public int BuildNumber { get; set; }

    public override bool Execute()
    {
        BuildNumber = GetLatestVersionNumber();
        return true;
    }

    private int GetLatestVersionNumber()
    {
        var process = new RunProcess();
        var result = process.ExecuteCommand(TfsCommand, TfsArgument);

        return ParseResult(result);
    }

    private int ParseResult(string result)
    {
        const string changeset = "Changeset:";
        const string user = "User:";

        if (string.IsNullOrEmpty(result) || !result.Contains(changeset))
        {
            // Invalid result
            Log.LogWarning("Could not get latest build number. Reason: " + result);
            return 0;
        }

        var indexOfChangeset = result.IndexOf(changeset, StringComparison.InvariantCulture) + changeset.Length;
        var indexOfUser = result.IndexOf(user, StringComparison.InvariantCulture);
        var revision = result.Substring(indexOfChangeset, indexOfUser - indexOfChangeset).Trim();

        return Convert.ToInt32(revision);
    }

}

这篇关于获取TFS把变更的程序集版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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