Get Tfs Shelveset file contents at the command prompt?

前端 未结 6 1162

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:19

    This is what I ended up with, based on pentelif's code and the technique in the article at http://akutz.wordpress.com/2010/11/03/get-msi/ linked in my comment.

    function Get-TfsShelvesetItems
    {
        [CmdletBinding()]
        param
        (
            [string] $ShelvesetName = $(throw "-ShelvesetName must be specified."),
            [string] $ShelvesetOwner = "$env:USERDOMAIN\$env:USERNAME",
            [string] $ServerUri = $(throw "-ServerUri must be specified."),
            [string] $Collection = $(throw "-Collection must be specified.")
        )
    
        $getShelvesetItemsClassDefinition = @'
        public IEnumerable GetShelvesetItems(string shelvesetName, string shelvesetOwner, string tfsUriString, string tfsCollectionName)
        {
            Uri tfsUri = new Uri(tfsUriString);
            TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
            ReadOnlyCollection collectionNodes = configurationServer.CatalogNode.QueryChildren( new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None);
            CatalogNode collectionNode = collectionNodes.Where(node => node.Resource.DisplayName == tfsCollectionName).SingleOrDefault();
            Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
            TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);
            var vcServer = teamProjectCollection.GetService();
            var changes = new List();
            foreach (Shelveset shelveset in vcServer.QueryShelvesets(shelvesetName, shelvesetOwner))
            {
                foreach (PendingSet set in vcServer.QueryShelvedChanges(shelveset))
                {
                    foreach ( PendingChange change in set.PendingChanges )
                    {
                        changes.Add(change);
                    }
                }
            }
            return changes.Count == 0 ? null : changes;
        }
    '@;
    
        $getShelvesetItemsType = Add-Type `
            -MemberDefinition $getShelvesetItemsClassDefinition `
            -Name "ShelvesetItemsAPI" `
            -Namespace "PowerShellTfs" `
            -Language CSharpVersion3 `
            -UsingNamespace System.IO, `
                            System.Linq, `
                            System.Collections.ObjectModel, `
                            System.Collections.Generic, `
                            Microsoft.TeamFoundation.Client, `
                            Microsoft.TeamFoundation.Framework.Client, `
                            Microsoft.TeamFoundation.Framework.Common, `
                            Microsoft.TeamFoundation.VersionControl.Client `
            -ReferencedAssemblies "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll", `
                                    "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Common.dll", `
                                    "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.VersionControl.Client.dll" `
            -PassThru;
    
        # Initialize an instance of the class.
        $getShelvesetItems = New-Object -TypeName "PowerShellTfs.ShelvesetItemsAPI";
    
        # Emit the pending changes to the pipeline.
        $getShelvesetItems.GetShelvesetItems($ShelvesetName, $ShelvesetOwner, $ServerUri, $Collection);
    }
    

提交回复
热议问题