让 TFS 将变更集放在程序集版本中 [英] Getting TFS to put the changeset in the assembly version
问题描述
我的 Team Foundation Server Build 运行正常.它生成多个程序集,我希望程序集版本的最后一个数字是 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.
我将如何实现这一点?
推荐答案
最后我的一个同事写了下面的 MSBuild 任务解决了这个问题.
In the end a colleague of 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屋!