繁体   English   中英

如何使用 PowerShell 脚本从 TFS 下载特​​定的标记代码?

[英]How to download a specific labelled code from TFS using PowerShell Script?

我有一个 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 结果

在此处输入图片说明

试试这个(对我有用):

$vs = New-Object Microsoft.TeamFoundation.VersionControl.Client.LabelVersionSpec($label, $scope);
foreach ($item in $VersionControl.GetItems($serverPath, $vs,$recursionType).Items)  
{
  .....
}

$label - 你的标签名称

$scope - 标签的范围(项目)。 要通过 VisualStudio 进行验证,请导航到File-> Source control-> Find-> Find Label 在“查找标签”表单中找到您的标签并打开它,然后您将看到项目名称(集合下的名称),您可以将其用作范围。

LabelVersionSpec 构造函数

更新

根据@SRP 的要求,您应该如何从 TFS 标签创建分支:

$vcs = $server.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer]); 
$changesetId = $vcs.CreateBranch($sourceBranch, $destBranch,$vs)

VersionControlServer.CreateBranch

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM