Get list files from a changeset using Microsoft.Te

2020-08-04 04:43发布

I use TFS 2008 in a company.

How can I get list of files from a TFS changeset using Microsoft.TeamFoundation.Client and Powershell ?

My script:

Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.VersionControl.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll"

2条回答
相关推荐>>
2楼-- · 2020-08-04 05:15
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.VersionControl.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll"

$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsServer) 
$versionControlType = [Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer] 
$versionControlServer = $tfs.GetService($versionControlType) 

$latest = [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest
$recursionType = [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full # 'Full'

# If specified, format should be like "Dyyyy-MM-ddThh:mm". 
#.EXAMPLE      C:\Export-TFS-Changes-To-Excel.ps1 -dateFrom D2014-10-20T00:00 -dateTo D2014-10-24T00:00 

$dateFrom = "D2015-03-17T00:00" 
$dateTo = "D2015-05-05T00:00" 

$userName = $null 
$versionFrom = $null 
$versionFrom = [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::ParseSingleSpec($dateFrom, "") 
$versionTo = $null 
$versionTo = [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::ParseSingleSpec($dateTo, "") 


$path="c:\MyProject\SpecialFolder\*"
$path="$/TeamProject/Main/Portal-branch"
$locationToSearch = $path

$vCSChangeSets = $versionControlServer.QueryHistory($locationToSearch, $latest, 0, $recursionType, $userName, $versionFrom, $versionTo, [int32]::MaxValue, $true ,$false, $false, $true) 
$TargetChangeSetChangeItems = @()  


$TargetChangeSetChangeItems = foreach ($vCSChangeSet in $vCSChangeSets) 
{   
    foreach ($vCSChange in $vCSChangeSet.Changes) 
    { 
        $vCSItem =  $vCSChange.Item 

        # MORE CODE HERE, OMMITTED
    }
}

References:
https://gallery.technet.microsoft.com/scriptcenter/Export-Foundation-Server-b664c8ce

查看更多
混吃等死
3楼-- · 2020-08-04 05:23

Maybe using VersionControlServer

$tfsServer = "http://server:8080"

Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.VersionControl.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll"

#Set up connection to TFS Server and get version control 
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsServer) 
$versionControlType = [Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer] 
$versionControlServer = $tfs.GetService($versionControlType) 
查看更多
登录 后发表回答