Command line 是否在命令提示下获取Tfs搁置集文件内容?

Command line 是否在命令提示下获取Tfs搁置集文件内容?,command-line,powershell,tfs,shelveset,Command Line,Powershell,Tfs,Shelveset,我对在命令提示符下获取搁置集的内容感兴趣。现在,您可能认为TFS Power Tools中提供的诸如Get-TfsHelveSet之类的cmdlet可以做到这一点。您可能还认为“tf.exe搁置集”可以做到这一点 然而,除非我遗漏了什么,否则我很震惊地报告说,这两个都不是事实。相反,每个命令都要求您为其指定一个搁置集名称,然后简单地为该搁置集返回一个单行项,以及有关搁置集的一些元数据,如creationdate、displayname等。但据我所知,无法确定该搁置集中的实际内容 这对于Get-T

我对在命令提示符下获取搁置集的内容感兴趣。现在,您可能认为TFS Power Tools中提供的诸如Get-TfsHelveSet之类的cmdlet可以做到这一点。您可能还认为“tf.exe搁置集”可以做到这一点

然而,除非我遗漏了什么,否则我很震惊地报告说,这两个都不是事实。相反,每个命令都要求您为其指定一个搁置集名称,然后简单地为该搁置集返回一个单行项,以及有关搁置集的一些元数据,如creationdate、displayname等。但据我所知,无法确定该搁置集中的实际内容

这对于Get-TfsShelveset来说尤其糟糕,它能够在返回Shelveset对象的同时包含一个文件描述符数组。我甚至试着变得聪明起来,认为我可以通过使用-WhatIf和Restore-TfsShelveset来获取文件名,但遗憾的是Restore-TfsShelveset没有实现-WhatIf

拜托,有人告诉我我错了

试试看:

tfpt审查 /搁置集:搁置集名称;用户名

您可能还需要添加服务器选项,以便:

tfpt审查/搁置集:代码审查;吉姆 /服务器:公司来源


我认为这就是您所要寻找的。

可以构造一个使用TFS SDK的小型命令行应用程序,该应用程序返回给定搁置集中包含的文件列表。
以下示例假定了解搁置集名称及其所有者:

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<CatalogNode> 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<VersionControlServer>();

            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);
                }
            }
        }
    }
}
使用系统;
使用System.IO;
使用System.Collections.ObjectModel;
使用Microsoft.TeamFoundation.Client;
使用Microsoft.TeamFoundation.Framework.Common;
使用Microsoft.TeamFoundation.Framework.Client;
使用Microsoft.TeamFoundation.VersionControl.Client;
命名空间搁置集详细信息
{
班级计划
{
静态void Main(字符串[]参数)
{
Uri tfsUri=(args.Length<1)?新Uri(“TFS_Uri”):新Uri(args[0]);
TfsConfigurationServer configurationServer=TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
ReadOnlyCollection collectionNodes=configurationServer.CatalogNode.QueryChildren(
新[]{CatalogResourceTypes.ProjectCollection},
错误,目录查询选项。无);
CatalogNode collectionNode=collectionNodes[0];
Guid collectionId=新Guid(collectionNode.Resource.Properties[“InstanceId”]);
TfsTeamProjectCollection teamProjectCollection=configurationServer.GetTeamProjectCollection(collectionId);
var vcServer=teamProjectCollection.GetService();
搁置集[]搁置=vcServer.QueryShelvesets(
“货架名称”、“货架所有者”);
搁置集搁置集=搁置[0];
PendingSet[]集=vcServer.QueryShelvedChanges(搁置集);
foreach(一组中的挂起集)
{
PendingChange[]changes=set.PendingChanges;
foreach(变更中的待定变更)
{
Console.WriteLine(change.FileName);
}
}
}
}
}

调用此控制台应用程序并在powershell执行期间捕获结果应该是可能的。

这就是我最终得到的结果,基于pentelif的代码和我评论中链接的文章中的技术

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<PendingChange> GetShelvesetItems(string shelvesetName, string shelvesetOwner, string tfsUriString, string tfsCollectionName)
    {
        Uri tfsUri = new Uri(tfsUriString);
        TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
        ReadOnlyCollection<CatalogNode> 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<VersionControlServer>();
        var changes = new List<PendingChange>();
        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);
}
函数获取TFSShelvestItems
{
[CmdletBinding()]
param
(
[string]$ShelvesetName=$(必须指定-ShelvesetName。“),
[string]$ShelvesetOwner=“$env:USERDOMAIN\$env:USERNAME”,
[string]$ServerUri=$(必须指定-ServerUri。“),
[string]$Collection=$(必须指定throw“-Collection”)
)
$GetShelvestItemsClassDefinition=@'
public IEnumerable GetShelvesetItems(字符串shelvesetName、字符串shelvesetOwner、字符串tfsUriString、字符串tfsCollectionName)
{
Uri-tfsUri=新的Uri(tfsuristing);
TfsConfigurationServer configurationServer=TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
ReadOnlyCollectionNodes=configurationServer.CatalogNode.QueryChildren(新[]{CatalogResourceTypes.ProjectCollection},false,CatalogQueryOptions.None);
CatalogNode collectionNode=collectionNodes.Where(node=>node.Resource.DisplayName==tfsCollectionName.SingleOrDefault();
Guid collectionId=新Guid(collectionNode.Resource.Properties[“InstanceId”]);
TfsTeamProjectCollection teamProjectCollection=configurationServer.GetTeamProjectCollection(collectionId);
var vcServer=teamProjectCollection.GetService();
var changes=新列表();
foreach(vcServer.QueryShelvesets中的搁置集搁置集(搁置集名称,搁置所有者))
{
foreach(vcServer.QueryShelvedChanges(搁置集)中的挂起集)
{
foreach(集合中的PendingChange更改。PendingChanges)
{
更改。添加(更改);
}
}
}
返回更改。计数==0?空:更改;
}
'@;
$getShelvesetItemsType=添加类型`
-MemberDefinition$getShelvesetItemsClassDefinition`
-名称“Shelvesettemsapi”`
-命名空间“PowerShellTfs”`
-语言CSharpVersion3`
-使用namespace System.IO`
系统Linq`
System.Collections.ObjectModel`
System.Collections.Generic`
Microsoft.TeamFoundation.Client`
Microsoft.TeamFoundation.Framework.Client`
Microsoft.TeamFoundation.Framework.Common`
Microsoft.TeamFoundation.VersionControl.Client`
-ReferenceAssemblys“C:\Program Files(x86)\Microsoft Visual Studio 10.0\Co
tf status /shelveset:name
Get-TfsPendingChange -Shelveset name