如何以编程方式合并TFS变更集?
问题描述:
我知道如何使用命令行命令"tf merge"合并TFS 2010中的更改集.
I know how to merge a change set in TFS 2010 using the command line command "tf merge".
有没有一种方法可以在C#中使用代码来完成此操作.我只想一次合并一个特定的变更集(樱桃选择).
Is there a way I can do this in C# with code. I want to merge specific change sets only (cherry pick), one at a time.
答
如果您使用的是2010或2012 TFS对象模型,这大致就是您要执行的操作.如果您有任何问题,请告诉我.
This is roughly how you would do it if you were working with the 2010 or 2012 TFS object models. Let me know if you have any questions.
// Get a reference to yourTeam Foundation Server.
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("http://<yourserver>:8080/tfs/<yourcollection> "));
// Get a reference to Version Control.
VersionControlServer versionControl = tpc.GetService<VersionControlServer>();
Workspace workspace = versionControl.GetWorkspace("<local path to your workspace>");
string sourceBranch = "$/<sourceBranch>";
string targetBranch = "$/<targetBranch>";
VersionSpec changesetToMerge = new ChangesetVersionSpec(<your changeset here>);
// actually pend the merge
workspace.Merge(sourceBranch, targetBranch, changesetToMerge, changesetToMerge);
// check in the merge
workspace.CheckIn(workspace.GetPendingChanges(), "your comment");