我有以下函数在两个新项目的循环中被调用以添加到源代码管理中。循环的每次迭代都会获取源代码,将其复制到文件夹中,创建一个 tfs 团队项目,为该项目创建一个工作区,然后尝试将代码添加到源代码管理中。
static void Main(string[] args) {
var tfsWorkItems = _<IWorkItems>();
var workItems = tfsWorkItems.GetProjectsToMigrate();
var tfs = _<ITfs>();
var logFilePath = new DirectoryInfo("C:\\log");
var workingDirectory = new DirectoryInfo("C:\\m");
Cleanup(workItems, tfs, logFilePath, workingDirectory);
var svn = _<ISvn>();
var app = _<IApplication>();
foreach (var workItem in workItems)
{
var root = Path.Combine(workingDirectory.FullName, workItem.Id.ToString());
var svnBase = Path.Combine(root, "s");
var localWorkspacePath = Path.Combine(root, "t");
var tfsBase = Path.Combine(localWorkspacePath, workItem.TfsProjectName, "Main");
var tfsProject = workItem.ProjectType.ToLower() == "php" ? Path.Combine(tfsBase, "src")
: tfsBase;
svn.CheckoutFromSvn(workItem.SvnLocation, svnBase);
app.CopyToTfsFolderStructure(svnBase, tfsProject);
tfs.CreateTeamProject(workItem.TfsProjectName, logFilePath);
tfs.CreateWorkspace(workItem.WorkspaceName, localWorkspacePath);
tfs.AddToSourceControl(workItem.WorkspaceName, localWorkspacePath, workItem.TfsProjectName);
}
}
有两个项目。第一个项目正常工作,但第二个项目没有。第二个项目创建项目和工作区,但在 AddToSourceControl
public void AddToSourceControl(string workspaceName, string localPath, string projectName) {
var tfs = new TfsTeamProjectCollection(_collection);
var vcs = tfs.GetService<VersionControlServer>();
var user = vcs.AuthorizedUser;
var workspace = vcs.GetWorkspace(workspaceName, user);
var serverPath = workspace.GetServerItemForLocalItem(Path.Combine(localPath, projectName, "Main"));
var itemSpec = new ItemSpec[] {
new ItemSpec(serverPath, RecursionType.Full)
};
workspace.PendAdd(serverPath, true);
// doesn't return anything
var pendingSets = vcs.QueryPendingSets(
itemSpec, workspace.Name, user, true);
var pendingChanges = pendingSets.Aggregate(new List<PendingChange>(), (acc, item) => {
acc.AddRange(item.PendingChanges);
return acc;
});
var parameters = new WorkspaceCheckInParameters(pendingChanges, "svn to tfs migration") {
OverrideGatedCheckIn = ((CheckInOptions2)vcs.SupportedFeatures & CheckInOptions2.OverrideGatedCheckIn) == CheckInOptions2.OverrideGatedCheckIn,
PolicyOverride = new PolicyOverrideInfo("migration triggered check-in", null),
SuppressEvent = true,
};
workspace.CheckIn(parameters);
}
workspace.PendAdd(serverPath, true)
总是为第二个项目返回零,无论哪个项目是第二个。第一个项目总是正确完成。哪个项目是第二个并不重要。第二个项目总是返回零项。我显然希望所有项目都正确添加到源代码管理中。这里发生了什么?