我正在开发一个应用程序,该应用程序可从指定路径中获取少量文件,然后单击按钮即可移至TFS。我的第一个问题是,是否可以使用C#以编程方式向TFS添加新文件?如果是,那么我们可以添加到TFS的文件类型是否有任何限制?下面是我尝试在TFS中创建工作区的代码。
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(<tfs uri>));
tfs.EnsureAuthenticated();
VersionControlServer vcs = tfs.GetService<VersionControlServer>();
Workspace ws = vcs.CreateWorkspace("DCSCode");
//"I:temp" is the location of files which needs to be
//moved to TFS
int r = ws.PendAdd(@"I:temp");
答案 0 :(得分:0)
如果需要,您需要create a new or get the existing workspace
-> pend changes
-> check in those changes
-> resolve the conflict
。
相关代码段供您参考:
//Get the current workspace
WS = versionControl.GetWorkspace(workspaceName, versionControl.AuthorizedUser);
//Mapping TFS Server and code generated
WS.Map(tfsServerFolderPath,localWorkingPath);
//Add all files just created to pending change
int NumberOfChange = WS.PendAdd(localWorkingPath,true);
//Get the list of pending changes
PendingChange[] pendings = WS.GetPendingChanges(tfsServerFolderPath,RecursionType.Full);
//Auto check in code to Server
WS.CheckIn(pendings,"CodeSmith Generator - Auto check-in code.");
您还可以在这里找到示例:Programatically checkin file to TFS using C#