2012-02-10 32 views
7

Có cách nào để có được phiên bản thay đổi mới nhất theo chương trình nói chung hay không.Nhận số đăng ký mới nhất (id thay đổi mới nhất)

Đó là khá dễ dàng để có được id changeset cho tập tin nhất định:

var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://my.tfs.com/DefaultCollection")); 
     tfs.EnsureAuthenticated(); 
     var vcs = tfs.GetService<VersionControlServer>(); 

và sau đó gọi GetItems hoặc QueryHistory, nhưng tôi muốn biết số checkin cuối cùng là gì.

Trả lời

9

Bạn có thể làm điều đó như thế này:

var latestChangesetId = 
    vcs.QueryHistory(
     "$/", 
     VersionSpec.Latest, 
     0, 
     RecursionType.Full, 
     String.Empty, 
     VersionSpec.Latest, 
     VersionSpec.Latest, 
     1, 
     false, 
     true) 
     .Cast<Changeset>() 
     .Single() 
     .ChangesetId; 
+5

Dường VersionControlServer cũng có một phương pháp GetLatestChangesetId. Nó ngắn hơn nhiều :-) – tbaskan

+0

chúng ta có thể chuyển tên người dùng và pwd cho kết nối dưới đây tfs 'var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection (new Uri (tfsServer)); tfs.Connect (ConnectOptions.None); ' bcoz sau khi triển khai các trang web của tôi đến máy chủ IIS i m không thể lấy chi tiết tfs nhưng đối với localhost tôi có thể nhận được chi tiết tfs cho cùng một trang web. i m nhận được dưới đây err Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: TF30063: Bạn không được phép truy cập http: // tfsserver: 8080/tfs/mycollection. tại Microsoft.TeamFoundation.Client.TfsConnection.ThrowAuthorizationException (Ngoại lệ e) – picnic4u

+0

@ picnic4u có lẽ tốt nhất là nâng cao câu hỏi mới cho điều đó. – DaveShaw

0

tôi sử dụng sau lệnh tf cho điều này

/// <summary> 
    /// Return last check-in History of a file 
    /// </summary> 
    /// <param name="filename">filename for which history is required</param> 
    /// <returns>TFS history command</returns> 
    private string GetTfsHistoryCommand(string filename) 
    { 
     //tfs history command (return only one recent record stopafter:1) 
     return string.Format("history /stopafter:1 {0} /noprompt", filename); // return recent one row 
    } 

sau khi thực hiện tôi phân tích đầu ra của lệnh này để có được changeset số

using (StreamReader Output = ExecuteTfsCommand(GetTfsHistoryCommand(fullFilePath))) 
     { 
      string line; 
      bool foundChangeSetLine = false; 
      Int64 latestChangeSet; 
      while ((line = Output.ReadLine()) != null) 
      { 
       if (foundChangeSetLine) 
       { 
        if (Int64.TryParse(line.Split(' ').First().ToString(), out latestChangeSet)) 
        { 
         return latestChangeSet; // this is the lastest changeset number of input file 
        } 
       } 
       if (line.Contains("-----"))  // output stream contains history records after "------" row 
        foundChangeSetLine = true; 
      } 
     } 

này làm thế nào tôi thực hiện lệnh

/// <summary> 
    /// Executes TFS commands by setting up TFS environment 
    /// </summary> 
    /// <param name="commands">TFS commands to be executed in sequence</param> 
    /// <returns>Output stream for the commands</returns> 
    private StreamReader ExecuteTfsCommand(string command) 
    { 
     logger.Info(string.Format("\n Executing TFS command: {0}",command)); 
     Process process = new Process(); 
     process.StartInfo.CreateNoWindow = true; 
     process.StartInfo.FileName = _tFPath; 
     process.StartInfo.UseShellExecute = false; 
     process.StartInfo.RedirectStandardOutput = true; 
     process.StartInfo.RedirectStandardInput = true; 
     process.StartInfo.Arguments = command; 
     process.StartInfo.RedirectStandardError = true; 
     process.Start(); 
     process.WaitForExit();            // wait until process finishes 
     // log the error if there's any 
     StreamReader errorReader = process.StandardError; 
     if(errorReader.ReadToEnd()!="") 
      logger.Error(string.Format(" \n Error in TF process execution ", errorReader.ReadToEnd())); 
     return process.StandardOutput; 
    } 

Không phải là một cách hiệu quả nhưng vẫn là một giải pháp này hoạt động trong TFS 2008, hy vọng điều này sẽ giúp.

1

Sử dụng VersionControlServer.GetLatestChangesetId để có được id changeset mới nhất, như đã đề cập bởi người dùng tbaskan trong các ý kiến.

(Trong TFS Java SDK nó VersionControlClient.getLatestChangesetId)

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