我有一个 PS 脚本,它从本地机器上的 TFS 下载最新代码,但我希望它下载特定标记代码而不是最新代码。
下面是下载 TFS 中最新代码的脚本,
$sourceLocation = "http://vwmaztfsapp:8080/tfs/MatchCollection"
$tfsCollectionUrl = New-Object System.URI($sourceLocation);
$serverPath = "$/Match Web/Installscript Projects/Utility Scripts"
#It gets copied at local path with the above folder sequence
$localPath = "C:\"
$visualStudiopath = 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer'
Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.VersionControl.Client.dll"
Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Common.dll"
Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Client.dll"
Add-type -path "$visualStudiopath\Microsoft.TeamFoundation.ProjectManagement.dll"
Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Build.Common.dll"
$tfsCollection = New-Object -TypeName Microsoft.TeamFoundation.Client.TfsTeamProjectCollection -ArgumentList $tfsCollectionUrl
$VersionControl = $tfsCollection.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
$latest = [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest
$recursionType = [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full
try
{
foreach ($item in $VersionControl.GetItems($serverPath, $latest,$recursionType).Items)
{
$target = [io.path]::Combine($localPath,$item.ServerItem.Substring(2))
$exists=[System.IO.Directory]::Exists($target)
if($item.ItemType -eq "Folder" -and !$exists)
{
New-Item $target -Type Directory
}
if($item.ItemType -eq "File")
{
$item.DownloadFile($target)
}
}
Write-Host "`n Successfully downloaded all the files to the target folder: " $localPath -ForegroundColor Green
}
catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Break
}
我尝试使用Microsoft.TeamFoundation.VersionControl.Client.LabelVersionSpec
但没有成功。谁能指导我找到正确的链接或脚本,通过它我可以使用我在其上应用的标签下载“$/Match Web”代码。这是我在“$/Match Web”分支上应用的标签,例如 -“PreBuildLabel-MatchEnterpriseBuild1”
@Assael Azran,低于 $vs 的结果