Get Tfs Shelveset file contents at the command prompt?

前端 未结 6 1142

I\'m interested in getting the contents of a shelveset at the command prompt. Now, you would think that a cmdlet such as Get-TfsShelveset, available in the TFS Power Tools,

6条回答
  •  天涯浪人
    2020-12-18 04:14

    It is possible to construct a small command-line application that uses the TFS SDK, which returns the list of files contained in a given shelveset.
    The sample below assumes knowledge of the Shelveset name & it's owner:

    using System;
    using System.IO;
    using System.Collections.ObjectModel;
    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.Framework.Common;
    using Microsoft.TeamFoundation.Framework.Client;
    using Microsoft.TeamFoundation.VersionControl.Client;
    
    namespace ShelvesetDetails
    {
        class Program
        {
            static void Main(string[] args)
            {
                Uri tfsUri = (args.Length < 1) ? new Uri("TFS_URI") : new Uri(args[0]);
    
                TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
    
                ReadOnlyCollection collectionNodes = configurationServer.CatalogNode.QueryChildren(
                    new[] { CatalogResourceTypes.ProjectCollection },
                    false, CatalogQueryOptions.None);
    
                CatalogNode collectionNode = collectionNodes[0];
    
                Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
                TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);
    
                var vcServer = teamProjectCollection.GetService();
    
                Shelveset[] shelves = vcServer.QueryShelvesets(
                    "SHELVESET_NAME", "SHELVESET_OWNER");
                Shelveset shelveset = shelves[0];
    
                PendingSet[] sets = vcServer.QueryShelvedChanges(shelveset);
                foreach (PendingSet set in sets)
                {
                    PendingChange[] changes = set.PendingChanges;
                    foreach (PendingChange change in changes)
                    {
                        Console.WriteLine(change.FileName);
                    }
                }
            }
        }
    }
    

    Invoking this console app & catching the outcome during execution of the powershell should be possible.

提交回复
热议问题