簡體   English   中英

用於 TFS 的 Visual Studio 加載項:標記要刪除的文件

[英]Visual Studio Add-In for TFS: Marking Files for Deletion

我一直在為我的公司編寫一個 VB 插件,它將 go 轉換為 TFS 並自動標記以“.delete”結尾的文件以進行刪除。 為此,我想創建一個工作區“Temp”,它映射到我本地的 D:\TFSTemp 和 TFS 中的文件夾。 然后,我只想將 .delete 文件下載到我的本地(以避免必須獲取服務器中所有文件的最新信息),map 將它們從我的本地下載到服務器,將它們標記為刪除(workspace.PendDelete( )) 然后一次檢查它們。

我的問題是我不確定我是否設置了所需的正確映射。 我能夠下載所有 the.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");

在將項目獲取到本地工作區之前,您無法掛起刪除。

您當前正在執行DownloadFile ,它只會獲取文件的內容 - 它不會更新您的工作區以反映您在本地擁有該文件。 在等待刪除之前,您應該為該文件調用Workspace.Get

另一項:您不應該對文件使用完全遞歸(不知道后果),您可能應該使用RecursionType.None 文件的完全遞歸執行模式匹配,並將包含給定路徑下具有該文件名的所有文件。 (即,$/file.txt 的完全遞歸將匹配 $/file.txt、$/A/file.txt、$/A/B/file.txt 等)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM