我正在尝试创建一个Powershell脚本,该脚本将在临时位置设置一个全新的工作区,对选定的解决方案/项目执行GetLatest,并下载源代码,以便我可以触发进一步的构建/版本控制操作。
我认为我的脚本或多或少是正确的,但问题是每次我运行它时,它告诉我有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"
答案 0 :(得分:1)
$tfsServer = "http://tfsserver:8080/tfs"
应为$tfsServer = "http://tfsserver:8080/tfs/nameOfACollection"
答案 1 :(得分:0)
"$/Client1/Project1"
字符串闻起来。我会在美元符号之前添加一个反引号,因此它不会被读作变量或使用单引号。
BACKTICK
"`$/Client1/Project1"
单引号
'$/Client1/Project1'