【发布时间】:2021-06-25 04:41:21
【问题描述】:
我想导出特定变更集和/或系列中的多个变更集的 TFS 源文件。文件应该导出到 D:\myTFSExport 文件夹。这不是现有的映射文件夹。
目的:在将代码上传到 TFS 后,我想提取并查看包含这些变更集的构建代码。
TFS Power Tool 的以下命令没有提及目标文件夹的选项。
tfpt getcs /changeset:changesetNo
提前致谢
【问题讨论】:
我想导出特定变更集和/或系列中的多个变更集的 TFS 源文件。文件应该导出到 D:\myTFSExport 文件夹。这不是现有的映射文件夹。
目的:在将代码上传到 TFS 后,我想提取并查看包含这些变更集的构建代码。
TFS Power Tool 的以下命令没有提及目标文件夹的选项。
tfpt getcs /changeset:changesetNo
提前致谢
【问题讨论】:
如何提取变更集列表
我正是有这个要求才能为发布创建补丁。我在 tfs 或 tfs 电动工具中找不到任何东西可以做到这一点,所以我自己写了。
要使用,语法如下:
GetTfsChangeSet.exe TfsServerUrl changsetIdList fileOutputPath [merge]
地点:
例如
GetTfsChangeSet.exe http://asdpwiap017:8080/tfs 1233,4555,3332 c:\deploy merge
创建控制台应用程序解决方案。
添加这些程序集引用:
程序.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace GetTfsChangeSet
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 3)
{
Console.WriteLine("Usage:");
Console.WriteLine("GetTfsChangeSet.exe TfsServerUrl changsetIds fileOutputPath [merge]");
Console.WriteLine();
Console.WriteLine("where:");
Console.WriteLine("- changsetIdList : comma separated list of changesets");
Console.WriteLine("- merge: With Merge param, combines all changesets into one folder. Without the param, each change set is output to a different folder.");
Console.WriteLine();
Console.WriteLine("e.g.");
Console.WriteLine(@"GetTfsChangeSet.exe http://asdpwiap017:8080/tfs 1233,4555,3332 c:\deploy merge");
//Console.ReadKey();
return;
}
string teamProjectCollectionUrl = args[0]; // "http://asdpwiap017:8080/tfs";
var changesets = args[1].Split(',');
string outputDir = args[2];
bool mergeChangeSets = args.Length >= 4 && args[3].ToLower().Equals("merge");
if (mergeChangeSets)
{
Console.WriteLine("Merge changesets " + args[1]);
}
TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamProjectCollectionUrl));
string downloadPath = "";
if (mergeChangeSets)
{
downloadPath = args[1].Replace(',', '-');
if (downloadPath.Length > 30)
{
downloadPath = downloadPath.Substring(0, 15) + "..." + downloadPath.Substring(downloadPath.Length-15);
}
downloadPath = Path.Combine(outputDir, downloadPath);
}
foreach (var changesetStr in changesets.OrderBy(c=>c))
{
var changeset = Convert.ToInt32(changesetStr);
if (!mergeChangeSets)
{
downloadPath = Path.Combine(outputDir, changeset.ToString());
}
var files = GetFilesAssociatedWithBuild(teamProjectCollection, changeset, downloadPath);
Console.WriteLine(string.Format("ChangeSet {0}: {1} files extracted.", changeset, files.Count));
}
Console.WriteLine("Done.");
//Console.ReadKey();
}
private static List<string> GetFilesAssociatedWithBuild(TfsTeamProjectCollection teamProjectCollection, int changesetId, string downloadPath)
{
List<string> files = new List<string>();
VersionControlServer versionControlServer = teamProjectCollection.GetService(typeof(VersionControlServer)) as VersionControlServer;
Changeset changeset = versionControlServer.GetChangeset(changesetId);
if (changeset.Changes != null)
{
foreach (var changedItem in changeset.Changes)
{
var item = changedItem.Item;
if (item.ItemType != ItemType.File || item.DeletionId != 0)
continue;
var outFilename = Path.Combine(downloadPath, item.ServerItem.Replace("$/", "").Replace("/", @"\"));
item.DownloadFile(outFilename);
files.Add(outFilename);
}
}
return files;
}
}
}
【讨论】:
Install-Package Microsoft.TeamFoundationServer.ExtendedClient -Version 15.112.1跨度>
http://asdpwiap017:8080/tfs/DefaultCollection
您可以简单地添加另一个映射到D:\myTFSExport 文件夹的工作区并使用
tf get $/MyProject /version:Cnnnn /recursive
nnnn 是所需的变更集编号。
【讨论】: