我一直在爲我的公司編寫一個VB加載項,它將進入TFS並自動標記以「.delete」結尾以刪除的文件。爲此,我想創建一個工作空間「Temp」,它映射到我本地的D:\ TFSTemp以及TFS中的一個文件夾。然後,我只想將.delete文件下載到本地(以避免必須獲取服務器中的所有文件的最新版本),將它們從本地映射到服務器,將它們標記爲刪除(workspace.PendDelete( )),然後立即檢查它們。TFS的Visual Studio加載項:標記要刪除的文件
我的問題是我不確定我是否設置了正確的映射。我可以下載所有的.delete文件,但是當我調用Workspace.GetPendingChanges()時,數組沒有被填充,這就是爲什麼我懷疑我可能沒有正確設置它。
我知道這是一個複雜的加載項,所以如果我的代碼對您沒有意義,請向我提問。
//establish connection to tfs
TeamFoundationServer server = new TeamFoundationServer(TFS1);
//test file to output to
StreamWriter xw = new StreamWriter(@"C:\Documents and Settings\A087649\Desktop\FileList.txt");
//get a working object in tfs
VersionControlServer sourceControl = server.GetService(typeof(VersionControlServer)) as VersionControlServer;
int numberOfFiles = 0;
int numToDelete = 0;
try
{
//load config file
//LoadConfig();
//path where we are going to look in tfs
String path = @"$/PAIT_ECOMPARE/Dev/TFSTool/Prod/Offeringdata/AU/CT";
//array of item objects in that path
ItemSet items = sourceControl.GetItems(path, RecursionType.Full);
numberOfFiles = items.Items.Length;
Workspace workspace = sourceControl.CreateWorkspace("Temp");
WorkingFolder workingFolder = new WorkingFolder(path, @"D:\TFSTemp\");
workspace.CreateMapping(workingFolder);
//instance of own created class that represents the progressbar and log output
TFSToolLoad ProgressBar = new TFSToolLoad();
ProgressBar.SetValues(numberOfFiles);
ProgressBar.TopMost = true;
foreach (Item item in items.Items)
{
ProgressBar.Show();
//get only the file path to the file
serverPath = item.ServerItem;
//get changeset Id
changeSetID = item.ChangesetId;
if (serverPath.EndsWith(".delete"))
{
//get file name only and local path
fileName = Path.GetFileName(serverPath);
localPath = @"D:\TFSTemp\"+ fileName;
//get latest on the file
workspace.Get(new GetRequest(serverPath, RecursionType.None, VersionSpec.Latest), GetOptions.None);
workspace.PendDelete(serverPath, RecursionType.None);
numToDelete++;
}
ProgressBar.Step();
}
ProgressBar.SetText
("Number of Files Marked for Delete: " + numToDelete+"\n");
//if there are any pending changes, check them in and merge them into staging
if (numToDelete > 0)
{
//check in all the changes
ProgressBar.SetText("Checking in changes...\n");
PendingChange[] pendingChanges = workspace.GetPendingChanges();
//if there are any pending changes, check them in and merge them into staging
workspace.CheckIn(pendingChanges, "Automated TFS tool cleanup");
ProgressBar.SetText("Done\n Merging changes into Staging...");
//merge
//set up merge by changeset id
ChangesetVersionSpec changeSet = new ChangesetVersionSpec(changeSetID);
//map to target server path before merging, otherwise it won't work
Workspace eCompareAdmin = sourceControl.GetWorkspace(@"D:\PAIT_ECOMPARE");
string mainPath = @"$/PAIT_ECOMPARE/Dev/TFSTool";
string stagingPath = @"$/PAIT_ECOMPARE/Dev/TFSToolStaging";
//Problem:
eCompareAdmin.Merge(mainPath, stagingPath, changeSet, changeSet);
PendingChange[] mergeChanges = eCompareAdmin.GetPendingChanges();
workspace.CheckIn(mergeChanges, "Automated TFS Cleanup");
ProgressBar.SetText("Done\n");
使用ChangesetVersionSpec。 –
謝謝愛德華!我有最後一個問題。一旦我執行合併,我想檢查目標分支的更改,但是當我執行GetPendingChanges()時,數組再次返回0.我一直在調試整天,似乎無法弄清楚這一點。我錯過了什麼?我已經更新了上面的代碼以反映我的更改。 –
這是一個很好的問題 - Workspace.PendDelete()調用是否成功?它會在成功時返回非零值,在失敗時返回零。 –