使用TFS API将代码检入TFS服务器

3

我正在编写 C# 代码,用于将代码提交到 TFS 服务器:

Workspace WS = VersionControl.GetWorkspace(TeamProject);
WS.Map(TFSMapServerPath,LocalWorkingPath);

int NumberOfChange = WS.PendAdd(string.Format(@"{0}\Main\DotNet\",LocalWorkingPath),true);

PendingChange[] pendingChanges = WS.GetPendingChanges();        
WS.CheckIn(pendingChanges,"Auto Check-in");

但是我遇到了错误:

"没有文件被签入",LocalWorkingPath下的所有文件/文件夹都是"待提交更改"。

以上代码是否正确?


获取最新版本并检查您的代码是否存在,有时代码已经检入但TFS却未写入。 - Hadash
我使用我的账户检查TFS服务器,文件/文件夹都在那里,但状态显示为“待提交更改”,我需要右键点击并选择“提交”来手动进行检查。 - Hoang Nguyen
如果团队项目已经存在,则文件或文件夹已成功签入,否则为“待更改”。如果TFS服务器中不存在团队项目,我们有什么自动签入的方法吗? - Hoang Nguyen
1
VersionControl.GetWorkspace接受本地工作区路径而不是团队项目。是的,项目必须存在才能针对它进行任何检入操作。 - allen
1个回答

2

我将命令WS.GetPendingChanges()更改为WS.GetPendingChanges(tfsServerFolderPath,RecursionType.Full),并且它在我的端上运行良好。

以下是详细信息:

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

你用什么参考来完成这个?提前感谢。 - Leandro Bardelli
这种方法对文件夹不起作用,当我尝试仅检入没有文件的文件夹时,会出现异常:“未检入任何文件”。 - Mr.B

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接