powershelltfstfsbuildtf-cli

"GetLatest" with Powershell doesn't download files on new TFS workspace


I'm trying to create a Powershell script that will setup a brand new workspace in a temporary location, do a GetLatest on selected solutions/projects, and download the source code so that I can then trigger further build/versioning operations.

I think I have the script more or less right, but the problem is every time I run this, it tells me there were 0 operations... i.e. I already have the latest versions. This results in nothing at all being downloaded.

Can anyone see what I'm doing wrong?

$subfolder = [System.Guid]::NewGuid().ToString()
$tfsServer = "http://tfsserver:8080/tfs"
$projectsAndWorkspaces = @(
    @("$/Client1/Project1","D:\Builds\$subfolder\Client1\Project1"),
    @("$/Client1/Project2","D:\Builds\$subfolder\Client1\Project2"),
)


$tfsCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsServer)
$tfsVersionCtrl = $tfsCollection.GetService([type] "Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer")
$tfsWorkspace = $tfsVersionCtrl.CreateWorkspace($subfolder, $tfsVersionCtrl.AuthorizedUser)

Write-Host "Operations:"

foreach ($projectAndWs in $projectsAndWorkspaces)
{
    if (-not(Test-Path $projectAndWs[1]))
    {
        New-Item -ItemType Directory -Force -Path $projectAndWs[1] | Out-Null
    }

    $tfsWorkspace.Map($projectAndWs[0], $projectAndWs[1])
    $recursion = [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full
    $itemSpecFullTeamProj = New-Object Microsoft.TeamFoundation.VersionControl.Client.ItemSpec($projectAndWs[0], $recursion)
    $fileRequest = New-Object Microsoft.TeamFoundation.VersionControl.Client.GetRequest($itemSpecFullTeamProj, [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest)
    $getStatus = $tfsWorkspace.Get($fileRequest, [Microsoft.TeamFoundation.VersionControl.Client.GetOptions]::Overwrite)
    Write-Host ("[{0}] {1}" -f $getStatus.NumOperations, ($projectAndWs[0].Substring($projectAndWs[0].LastIndexOf("/") + 1)))
}

Write-Host "Finished"

Solution

  • The $tfsServer = "http://tfsserver:8080/tfs" should be $tfsServer = "http://tfsserver:8080/tfs/nameOfACollection"