2015-05-20 11 views
6

Desidero esportare i file di origine TFS di un particolare changeset e/o più changeset di una serie. I file devono essere esportati per dire la cartella D: \ myTFSExport. Questa non è la cartella mappata esistente.Come esportare i file changeset di TFS in una cartella di destinazione

Lo scopo: voglio estrarre e rivedere i CODICI di Build che contengono questi changeset dopo che il codice è stato caricato in TFS.

Il seguente comando di TFS Power Tool non ha alcuna opzione per menzionare la cartella di destinazione.

getcs tfpt/changeset: changesetNo

Grazie in anticipo

risposta

0

Si può semplicemente aggiungere un altro spazio di lavoro che mappa alla cartella D:\myTFSExport e utilizzare

tf get $/MyProject /version:Cnnnn /recursive 

Dove nnnn è il numero di modifiche desiderato.

+0

Un suggerimento: y Puoi usare lo spazio di lavoro temporaneo, che elimini immediatamente. Quindi usa tf get o tfpt getcs – MichalMa

7

come estrarre un elenco di gruppi di modifiche

Ho avuto esattamente questo requisito al fine di creare patch per versioni. Non riuscivo a trovare nulla in tfs o tfs power tool per fare questo, quindi ho scritto il mio.

Per utilizzare, la sintassi è la seguente:

GetTfsChangeSet.exe TfsServerUrl changsetIdList fileOutputPath [merge] 

dove:

  • TfsServerUrl: Il server URL TFS
  • changsetIdList: elenco separato da virgole di changeset
  • fileOutputPath: Uscita percorso (non è necessario mappare)
  • unione: Con Merge param, combina tutte le cha ngeset in una cartella. Senza il parametro, ogni serie di modifiche viene inviata a una cartella diversa.

ad es.

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

creare una soluzione di un'applicazione console.

Aggiungere questi riferimenti di montaggio:

  • 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

Vorrei poter revocare questa risposta un centinaio di volte. Grazie mille Anton! – AFract

+2

Contento di aver potuto aiutare. – AntonK

+0

Per utilizzare questo codice su ** VS2017 ** è necessario NuGet: ** Microsoft.TeamFoundationServer.ExtendedClient ** Il comando della console NuGet di esempio è: 'Pacchetto di installazione Microsoft.TeamFoundationServer.ExtendedClient -Version 15.112.1' –