2012-02-10 37 views
7

Genel olarak programatik olarak en yeni olan değişiklikleri almanın bir yolu var mı.Son onay numarasını al (en son değişiklikler kümesi kimliği)

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

ve sonra GetItems veya QueryHistory diyoruz, ama son iade numarası ne olduğunu bilmek istiyorum:

Belli dosya için değişiklik kümesi id almak oldukça kolaydır.

cevap

9

Böyle yapabilirsin: Açıklamalarda tbaskan kullanıcı tarafından belirtildiği gibi

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

(TFS Java SDK yılında VersionControlClient.getLatestChangesetId var). – tbaskan

+0

çok kısaysa, kullanıcı adı ve pwd'yi tfs bağlantısının 'var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection (yeni Uri (tfsServer)) altından geçirebiliriz; tfs.Connect (ConnectOptions.None); bcoz web sayfalarımı IIS sunucusuna dağıttıktan sonra tfs ayrıntılarını alamıyorum ancak localhost için aynı web sayfaları için tfs ayrıntılarını alabiliyorum. aşağıdaki hata iletisini aldım Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: TF30063: http: // tfsserver: 8080/tfs/mycollection öğesine erişim yetkiniz yok. Microsoft.TeamFoundation.Client.TfsConnection.ThrowAuthorizationException (Exception e) – picnic4u

+0

@ picnic4u muhtemelen bunun için yeni bir soruyu en iyi şekilde yükseltiyor. – DaveShaw

0

ben komutunu çalıştırmak nasıl bu komutun çıktısı değişiklik kümesi sayısını

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; 
      } 
     } 

Bu almak için ayrıştırmak idamından sonra bu

/// <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 
    } 

için tf komutu aşağıdaki kullanın

/// <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; 
    } 

Bu etkili bir yol değil ama yine de bu TFS 2008'de işe yarıyor, umarım bu yardımcı olur.