gpt4 book ai didi

tfs - 如何将TFS变更集文件导出到目标文件夹

转载 作者:行者123 更新时间:2023-12-04 13:55:32 25 4
gpt4 key购买 nike

我想导出一个特定变更集和/或一系列变更集的TFS源文件。文件应导出到D:\myTFSExport文件夹。这不是现有的映射文件夹。

目的:在将代码上传到TFS之后,我想提取并查看包含这些变更集的Build的代码。

TFS Power Tool的以下命令没有任何提及目标文件夹的选项。

tfpt getcs/changeset:changesetNo

提前致谢

最佳答案

如何提取变更集列表

我完全有此要求,以便为发行版创建补丁。我在tfs或tfs电动工具中找不到任何东西可以做到这一点,所以我写了自己的东西。

要使用,语法如下:

GetTfsChangeSet.exe TfsServerUrl changsetIdList fileOutputPath [merge]

在哪里:
  • TfsServerUrl:TFS服务器URL
  • changsetIdList:逗号分隔的变更集列表
  • fileOutputPath:输出路径(不需要映射)
  • merge:使用Merge参数,将所有变更集组合到一个文件夹中。没有参数,每个更改集将输出到不同的文件夹。

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

    创建一个控制台应用程序解决方案。

    添加以下程序集引用:
  • 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;
    }
    }
    }

    关于tfs - 如何将TFS变更集文件导出到目标文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30347696/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com