TFS二次開發11——標籤(Label)

下圖是在VS2010裏建立Label的界面spa

 

能夠看出建立Label 須要以下參數:Name、Comment、Path、Version 。
下面是代碼實現:code

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

string tpcURL = "http://127.0.0.1:8080/";
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(tpcURL));
VersionControlServer versionControl = tpc.GetService(typeof(VersionControlServer)) as VersionControlServer;

//建立標籤
string labelName = "標籤名稱";
string labelComment = "標籤評論";
string path = "$/CRM/Branches/WeiMovie";
VersionSpec version = VersionSpec.Latest;
var versionControlLabel = new VersionControlLabel(versionControl, labelName, versionControl.AuthorizedUser, path, labelComment);

//Represents one or more files or folders on the local machine or in the repository.
var itemSpec = new ItemSpec(path, RecursionType.Full);
var labelItemSpec = new LabelItemSpec[1];
labelItemSpec[0] = new LabelItemSpec(itemSpec, version, false);
var lb = versionControl.CreateLabel(versionControlLabel, labelItemSpec, LabelChildOption.Merge);
//查詢標籤
VersionControlLabel[] lbls = versionControl.QueryLabels(null, null, null, true);//查詢所有標籤
//VersionControlLabel[] lbls = version.QueryLabels(null, null, null, false, path, VersionSpec.Latest);// 查詢指定路徑的標籤
//刪除標籤
versionControl.DeleteLabel(lbls[0].Name, lbls[0].Scope); 
相關文章
相關標籤/搜索