我一直在玩 TFS 一段时间,因为在本地创建和放置特定文件和文件夹后,我需要将它们上传/签入到 TFServer 上的各个位置。我正在映射工作区和所有内容,我从 PendingChanges 获得了一堆更改,但不是我想要的,也不是我想要的。这个问题真的很烦人,因为对于每个签入过程,我只想处理已经映射的特定位置的特定文件夹或文件。我将在此处粘贴部分代码以供参考。
using (TfsTeamProjectCollection collection = new TfsTeamProjectCollection(serverUri, _cred))
{
VersionControlServer versionControl = (VersionControlServer)collection.GetService(typeof(VersionControlServer));
string machineName = Environment.MachineName;
string currentUserName = Environment.UserName;
Workspace myWorkspace = versionControl.GetWorkspace(machineName, currentUserName);
// tried this from Stack but didn't work.
//PendingChange[] changes = myWorkspace.GetPendingChanges().Where(x => x.LocalOrServerFolder.Contains(localPath)).ToArray();
PendingChange[] changes = myWorkspace.GetPendingChanges();
if (changes.Length != 0)
{
foreach (PendingChange c in changes)
{
rt.Text += " path: " + c.LocalItem + ", change: " + PendingChange.GetLocalizedStringForChangeType(c.ChangeType) + "\n";
}
}
else
{
rt.Text += "This didn't work.";
}
}
基本上我想在我的 TFS 类中抛出一个文件夹或文件,让它检查文件或文件夹是否是最新的或存在于 TFS 上并采取相应的行动。我希望我已经彻底描述了这个问题。