2015-05-20 12 views
6

Tôi muốn xuất các tệp nguồn TFS của một thay đổi cụ thể và/hoặc nhiều bộ thay đổi trong một chuỗi. Tập tin nên được xuất khẩu để nói D: \ myTFSExport thư mục. Đây không phải là thư mục được ánh xạ hiện có.Cách xuất các tệp TFS changeset vào một thư mục đích

Mục đích: Tôi muốn trích xuất và xem lại các CODE xây dựng chứa các thay đổi sau khi Mã được tải lên TFS.

Lệnh sau của TFS Power Tool không có bất kỳ tùy chọn nào để đề cập đến thư mục Đích.

getcs tfpt/changeset: changesetNo

Cảm ơn trước

Trả lời

0

Bạn chỉ có thể thêm một không gian làm việc mà các bản đồ vào thư mục D:\myTFSExport và sử dụng

tf get $/MyProject /version:Cnnnn /recursive 

đâu nnnn là số changeset mong muốn.

+0

Một gợi ý: y Bạn có thể sử dụng không gian làm việc tạm thời mà bạn xóa ngay lập tức. Sau đó sử dụng tf get hoặc tfpt getcs – MichalMa

7

Làm thế nào để trích xuất một danh sách các changesets

tôi đã chính xác yêu cầu này để tạo các bản vá lỗi cho phiên bản. Tôi không thể tìm thấy bất cứ điều gì trong các công cụ điện tfs hoặc tfs để làm điều này, vì vậy tôi đã viết của riêng tôi.

Để sử dụng, cú pháp là một sau:

GetTfsChangeSet.exe TfsServerUrl changsetIdList fileOutputPath [merge] 

nơi:

  • TfsServerUrl: Các TFS máy chủ Url
  • changsetIdList: dấu phẩy tách ra danh sách các changesets
  • fileOutputPath: Output đường dẫn (không cần phải được ánh xạ)
  • hợp nhất: Với thông số Hợp nhất, kết hợp tất cả các cha ngesets vào một thư mục. Nếu không có tham số, mỗi bộ thay đổi sẽ xuất ra một thư mục khác.

ví dụ:

GetTfsChangeSet.exe http://asdpwiap017:8080/tfs 1233,4555,3332 c:\deploy merge 

Tạo giải pháp ứng dụng bảng điều khiển.

Thêm những tài liệu tham khảo lắp ráp:

  • Microsoft.TeamFoundation.Client
  • Microsoft.TeamFoundation.Common
  • Microsoft.TeamFoundation.VersionControl.Client

Program.cs

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Text; 
using Microsoft.TeamFoundation.Client; 
using Microsoft.TeamFoundation.VersionControl.Client; 

namespace GetTfsChangeSet 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 

      if (args.Length < 3) 
      { 
       Console.WriteLine("Usage:"); 
       Console.WriteLine("GetTfsChangeSet.exe TfsServerUrl changsetIds fileOutputPath [merge]"); 
       Console.WriteLine(); 
       Console.WriteLine("where:"); 
       Console.WriteLine("- changsetIdList : comma separated list of changesets"); 
       Console.WriteLine("- merge: With Merge param, combines all changesets into one folder. Without the param, each change set is output to a different folder."); 
       Console.WriteLine(); 
       Console.WriteLine("e.g."); 
       Console.WriteLine(@"GetTfsChangeSet.exe http://asdpwiap017:8080/tfs 1233,4555,3332 c:\deploy merge"); 

       //Console.ReadKey(); 
       return; 
      } 

      string teamProjectCollectionUrl = args[0]; // "http://asdpwiap017:8080/tfs"; 
      var changesets = args[1].Split(','); 
      string outputDir = args[2]; 
      bool mergeChangeSets = args.Length >= 4 && args[3].ToLower().Equals("merge"); 

      if (mergeChangeSets) 
      { 
       Console.WriteLine("Merge changesets " + args[1]); 
      } 

      TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamProjectCollectionUrl)); 
      string downloadPath = ""; 

      if (mergeChangeSets) 
      { 
       downloadPath = args[1].Replace(',', '-'); 
       if (downloadPath.Length > 30) 
       { 
        downloadPath = downloadPath.Substring(0, 15) + "..." + downloadPath.Substring(downloadPath.Length-15); 
       } 
       downloadPath = Path.Combine(outputDir, downloadPath); 
      } 


      foreach (var changesetStr in changesets.OrderBy(c=>c)) 
      { 
       var changeset = Convert.ToInt32(changesetStr); 
       if (!mergeChangeSets) 
       { 
        downloadPath = Path.Combine(outputDir, changeset.ToString()); 
       } 

       var files = GetFilesAssociatedWithBuild(teamProjectCollection, changeset, downloadPath); 

       Console.WriteLine(string.Format("ChangeSet {0}: {1} files extracted.", changeset, files.Count)); 
      } 

      Console.WriteLine("Done."); 
      //Console.ReadKey(); 
     } 

     private static List<string> GetFilesAssociatedWithBuild(TfsTeamProjectCollection teamProjectCollection, int changesetId, string downloadPath) 
     { 
      List<string> files = new List<string>(); 
      VersionControlServer versionControlServer = teamProjectCollection.GetService(typeof(VersionControlServer)) as VersionControlServer; 
      Changeset changeset = versionControlServer.GetChangeset(changesetId); 
      if (changeset.Changes != null) 
      { 
       foreach (var changedItem in changeset.Changes) 
       { 
        var item = changedItem.Item; 
        if (item.ItemType != ItemType.File || item.DeletionId != 0) 
         continue; 

        var outFilename = Path.Combine(downloadPath, item.ServerItem.Replace("$/", "").Replace("/", @"\")); 
        item.DownloadFile(outFilename); 

        files.Add(outFilename); 
       } 
      } 
      return files; 
     } 
    } 
} 
+3

Tôi ước tôi có thể upvote câu trả lời này hàng trăm lần. Cảm ơn bạn rất nhiều Anton! – AFract

+2

Vui vì tôi có thể giúp. – AntonK

+0

Để sử dụng mã này trên ** VS2017 **, bạn cần NuGet: ** Microsoft.TeamFoundationServer.ExtendedClient ** Ví dụ lệnh NuGet Console sẽ là: 'Gói cài đặt Microsoft.TeamFoundationServer.ExtendedClient -Phiên bản 15.112.1' –

Các vấn đề liên quan