"GetLatest" 使用 Powershell 不会在新的 TFS 工作区上下载文件

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

我正在尝试创建一个 Powershell 脚本,它将在一个临时位置设置一个全新的工作区,对选定的 solutions/projects 执行 GetLatest,然后下载源代码以便我可以进一步触发 build/versioning 操作。

我想我的脚本或多或少是正确的,但问题是每次我 运行 这个,它告诉我有 0 个操作...即我已经有最新版本。这导致什么都没有被下载。

谁能看出我做错了什么?

$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"

"$/Client1/Project1" 串有异味。我会在美元符号前添加一个反引号,这样它就不会被读取为变量或使用单引号。

反引号 "`$/Client1/Project1" 单引号 '$/Client1/Project1'

$tfsServer = "http://tfsserver:8080/tfs"应该是$tfsServer = "http://tfsserver:8080/tfs/nameOfACollection"