powershell - 将整个解决方案或特定分支从TFS下载到本地文件夹

标签 powershell tfs

大家好,我得到了下面的脚本,使用powershell脚本从TFS下载文件,但是我需要下载整个解决方案,我该如何实现

cls
$tfsCollectionUrl = New-Object System.URI("http://localhost:8080/tfs/defaultcollection");
[Microsoft.TeamFoundation.Client.TfsTeamProjectCollection] $tfsCollection = Get-TfsServer $tfsCollectionUrl
$VersionControl = $tfsCollection.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
$DestinationFile = [IO.Path]::GetTempFileName()
$VersionControl.DownloadFileByUrl('$/MyFirstProject/WebApplication1/WebApplication1/WebForm1.aspx.cs', $DestinationFile)

Invoke-Item $DestinationFile

另外,这不是在检查他是否具有下载权限,我想提示输入用户名和密码,而不是直接下载。我也可以在bitbucket上实现相同的功能吗

最佳答案

相同的代码转换为powershell

connect to tfs and download the files present in it VS2010

对于凭证,请使用上述逻辑

Write-Host "Enter source location "
$sourceLocation = Read-Host

$tfsCollectionUrl = New-Object System.URI($sourceLocation);

Write-Host "Enter server path "
$serverPath = Read-Host

Write-Host "Enter local path to download"
$localPath = Read-Host

[Microsoft.TeamFoundation.Client.TfsTeamProjectCollection] $tfsCollection = Get-TfsServer $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
}

关于powershell - 将整个解决方案或特定分支从TFS下载到本地文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38521110/

相关文章:

powershell - 以递归方式复制不包含子目录及其内容的目录

xml - 将工作项字段限制为 TFS 2010 中的特定用户

tfs - 有没有办法找出我没有同步到哪些变更集?

powershell - "Windows Powershell compatibility (.net standard 2.0)"是什么意思?

TFS checkin 错误 - 找不到文件

c# - 编辑 Resources.resx 文件时,Resources.Designer.cs 无法更新,因为 TFS 未将其 checkout

visual-studio - Visual Studio 2015 需要很长时间(10 - 15 分钟)在 TFS 的 "Get Latest"后重新加载项目

XML SelectSingleNode 区分大小写

excel - 使用 Excel 的 Powershell 脚本运行缓慢

iframe - 如何使用 Powershell 与 Iframe 交互?