C# 如何在自定义工作流活动中获取生成详细信息?
我需要向默认工作流模板添加自定义活动,以便在构建过程中尽早增加程序集版本 我想要实现的是在我的自定义活动中创建并映射完全相同的工作区(将在工作流中进一步创建),这样我就可以签出xml文件,增加其中的版本号,将其写回xml文件并签回xml文件 我知道此工作区将在稍后的工作流中创建,但对于我试图实现的目标来说,在构建过程中已经太晚了,因此不要移动任何活动或将其复制到自定义活动上方的位置(这应该可以,因为此工作区稍后将被删除并重新创建) 我想我需要的详细信息是BuildDirectory、WorkspaceName和SourcesDirectory。谁能告诉我如何创建工作区,或者如何在代码中获取这些数据 构建将在构建服务器上执行,我使用的是TFS2010和c#C# 如何在自定义工作流活动中获取生成详细信息?,c#,build,C#,Build,我需要向默认工作流模板添加自定义活动,以便在构建过程中尽早增加程序集版本 我想要实现的是在我的自定义活动中创建并映射完全相同的工作区(将在工作流中进一步创建),这样我就可以签出xml文件,增加其中的版本号,将其写回xml文件并签回xml文件 我知道此工作区将在稍后的工作流中创建,但对于我试图实现的目标来说,在构建过程中已经太晚了,因此不要移动任何活动或将其复制到自定义活动上方的位置(这应该可以,因为此工作区稍后将被删除并重新创建) 我想我需要的详细信息是BuildDirectory、Worksp
提前感谢我以一系列博客文章为基础,创建了一个自定义活动,用于签出、更新和签入我解析当前版本的GlobalAssemblyInfo文件。我的任务插入到“更新放置位置”的顶部,该位置正好在它执行工作流的“获取构建”部分之后。我只需要使用IBuildDetail和文件掩码作为参数,您可以从中拉出VersionControlServer以访问TFS。我的代码如下:
protected override string Execute(CodeActivityContext context)
{
// Obtain the runtime value of the input arguments.
string assemblyInfoFileMask = context.GetValue(AssemblyInfoFileMask);
IBuildDetail buildDetail = context.GetValue(BuildDetail);
var workspace = buildDetail.BuildDefinition.Workspace;
var versionControl = buildDetail.BuildServer.TeamProjectCollection.GetService<VersionControlServer>();
Regex regex = new Regex(AttributeKey + VersionRegex);
// Iterate of the folder mappings in the workspace and find the AssemblyInfo files
// that match the mask.
foreach (var folder in workspace.Mappings)
{
string path = Path.Combine(folder.ServerItem, assemblyInfoFileMask);
context.TrackBuildMessage(string.Format("Checking for file: {0}", path));
ItemSet itemSet = versionControl.GetItems(path, RecursionType.Full);
foreach (Item item in itemSet.Items)
{
context.TrackBuildMessage(string.Format("Download {0}", item.ServerItem));
string localFile = Path.GetTempFileName();
try
{
// Download the file and try to extract the version.
item.DownloadFile(localFile);
string text = File.ReadAllText(localFile);
Match match = regex.Match(text);
if (match.Success)
{
string versionNumber = match.Value.Substring(AttributeKey.Length + 2, match.Value.Length - AttributeKey.Length - 4);
Version version = new Version(versionNumber);
Version newVersion = new Version(version.Major, version.Minor, version.Build + 1, version.Revision);
context.TrackBuildMessage(string.Format("Version found {0}", newVersion));
return newVersion.ToString();
}
}
finally
{
File.Delete(localFile);
}
}
}
return null;
}
受保护的重写字符串执行(CodeActivityContext上下文)
{
//获取输入参数的运行时值。
字符串assemblyInfoFileMask=context.GetValue(assemblyInfoFileMask);
IBuildDetail buildDetail=context.GetValue(buildDetail);
var workspace=buildDetail.BuildDefinition.workspace;
var versionControl=buildDetail.BuildServer.TeamProjectCollection.GetService();
正则表达式正则表达式=新正则表达式(AttributeKey+VersionRegex);
//在工作区中迭代文件夹映射并查找AssemblyInfo文件
//和面具匹配。
foreach(workspace.Mappings中的var文件夹)
{
字符串路径=path.Combine(folder.ServerItem,assemblyInfoFileMask);
TrackBuildMessage(string.Format(“检查文件:{0}”,path));
ItemSet ItemSet=versionControl.GetItems(路径,RecursionType.Full);
foreach(itemSet.Items中的项)
{
TrackBuildMessage(string.Format(“下载{0}”,item.ServerItem));
字符串localFile=Path.GetTempFileName();
尝试
{
//下载文件并尝试解压缩版本。
item.DownloadFile(localFile);
string text=File.ReadAllText(localFile);
Match=regex.Match(文本);
如果(匹配成功)
{
string versionNumber=match.Value.Substring(AttributeKey.Length+2,match.Value.Length-AttributeKey.Length-4);
版本=新版本(版本号);
Version newVersion=新版本(Version.Major、Version.Minor、Version.Build+1、Version.Revision);
TrackBuildMessage(string.Format(“找到的版本{0}”,newVersion));
返回newVersion.ToString();
}
}
最后
{
Delete(localFile);
}
}
}
返回null;
}
感谢您的帮助,这是需要的!您是否知道是否有任何方法可以访问BuildDetail而不将其用作参数?只是好奇而已。我不知道有什么方法可以这样做。你可以使用context.GetExtension()
获取生成详细信息,而不将其作为参数传递。@谢谢您提供的信息。这对我将来会有帮助的。我不知道你能做到。