這篇文章給你們展現怎樣獲取一個文件的歷史版本,內容很簡單,直接上代碼了。spa
string tpcURL = "http://127.0.0.1:8080/"; TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(newUri(tpcURL)); VersionControlServer version = tpc.GetService(typeof(VersionControlServer)) as VersionControlServer; string serverDir = "$/MySolution/Customer/MAIN/App/SinaWeiTravel/SCRM.HPHY.Models"; //查詢歷史版本 var histories = version.QueryHistory(serverDir, VersionSpec.Latest,0, RecursionType.OneLevel, null, null, null, int.MaxValue, true, false); foreach(Changeset history inhistories) //遍歷路徑下的內容的全部歷史版本 { foreach(Change change inhistory.Changes)//每一個歷史版本下修改了幾個文件 { string serverItem = change.Item.ServerItem; string path = "D:\\" +change.Item.ChangesetId + "\\" +serverItem.Split('/').Last(); change.Item.DownloadFile(path); //下載該文件的此版本到指定位置 } }