以编程方式获取特定项目中特定文件夹的挂起更改?

时间:2012-09-19 18:55:34

标签: c# tfs2010

我一直在玩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上并采取相应的行动。我希望我已经彻底描述了这个问题。

1 个答案:

答案 0 :(得分:3)

我认为我的回答不会完全回答你的问题,但是如果你想获得特定文件夹的待定更改,你可以使用类似的东西..

PendingChange[] changes = myWorkspace.GetPendingChanges(localPath, RecursionType.Full, false);