How to merge TFS change sets programmatically?

穿精又带淫゛_ 提交于 2019-12-19 07:20:35

问题


I know how to merge a change set in TFS 2010 using the command line command "tf merge".

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.


回答1:


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");


来源:https://stackoverflow.com/questions/12092854/how-to-merge-tfs-change-sets-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!