简体   繁体   English

如何使用Powershell在TFS中获取特定项目的最新版本。

[英]How to get latest version of specific project in TFS using Powershell.

I've look through many posts but still don't get it. 我看过很多帖子,但仍然没有得到它。 I need a powershell script to download latest version of a specific project. 我需要一个powershell脚本来下载特定项目的最新版本。

Let's say I just want to download the latest copies of files from ProjectA branch dfe. 假设我只想从ProjectA分支dfe下载最新的文件副本。 I saw some PS script that deletes the old files and download all the files again but that takes too long. 我看到一些PS脚本删除旧文件并再次下载所有文件,但这需要太长时间。 script that would overwrite existing files would be much better. 将覆盖现有文件的脚本会好得多。 I tried update-tfsworkspace, it downloads everything but I don't want to download everything. 我尝试了update-tfsworkspace,它下载了所有内容,但我不想下载所有内容。 server: http://servername:8080/tfs/DefaultCollection server: http:// servername:8080 / tfs / DefaultCollection

DefaultCollection ProjectA -Folder1 - branch dfe -Folder2 - branch abc DefaultCollection ProjectA -Folder1 - branch dfe -Folder2 - branch abc

ProjectB -Folder1 - branch - branch ProjectB -Folder1 - 分支 - 分支

First you need a good workspace mapping. 首先,您需要一个良好的工作区映射 You can create one manually, or from an xml file as below. 您可以手动创建一个,也可以从xml文件创建,如下所示。 Also, the functionality you are after to overwrite is [Microsoft.TeamFoundation.VersionControl.Client.GetOptions]::Overwrite 此外,您要覆盖的功能是[Microsoft.TeamFoundation.VersionControl.Client.GetOptions] :: Overwrite

function Get-ProjectXml {
[CmdletBinding()]
Param(
    [string] $tfs13Url,
    [string] $workspaceName ,
    [string] $workspaceDescription,
    [string] $fileName,
    [bool] $autoDeleteCreate)

    try
    { 
        #Connect to TFS:
        $tfs13 = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfs13url)
        $vcs13 = $tfs13.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])

        $workspaces=$vcs13.QueryWorkspaces($workspaceName, $vcs13.AuthenticatedUser, [Environment]::MachineName);
        if($autoDeleteCreate ){
            #Delete if Workspace exists, as this is an automated process...
            if ($workspaces.count -gt 0)
            {
                $vcs13.DeleteWorkspace($workspaceName, $vcs13.AuthenticatedUser);
            }
            $workspace = $tfs10.VCS.CreateWorkspace($workspaceName, $vcs13.AuthenticatedUser, $workspaceDescription);
        }
        else
        {
            $workspace=$workspaces[0]
        }
        #Get XML File
        [xml]$xmlMappings= New-Object System.Xml.XmlDocument
        $xmlMappings.Load($fileName)
        $rootLocalItem=$xmlMappings.Root.LocalItem

        #Iterate through each collection
        foreach($collection in $xmlMappings.Collection){
            write-host "Mapping project $($collection.Name)"

            #Iterate through each project
            foreach($project in $collection.Project){
            write-host "Mapping project $($project.Name)"
            foreach($mapping in $project.Mapping){
                $workspace.Map($mapping.ServerItem, $mapping.LocalItem);
               }
            }
        }            
        $resultTime= Measure-Command {
            $result=$workspace.Get([Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest,[Microsoft.TeamFoundation.VersionControl.Client.GetOptions]::Overwrite)
        }
        $resultAlerts=$result.NumConflicts+ $result.NumFailures+ $result.NumWarnings
        if ($resultAlerts -eq 0) {
            Write-host "Get Operation completed without any errors. $($result.NumUpdated) files are updated on workspace: $($workspace.name)" }
        else {
            Write-Host "Get Operation completed with errors. Please check errors: $($result.GetFailures)"}
            $resultTime.ToString()
    }
    catch
    {
        return $_.exception
    }
}
[string] $tfs13Url="http://tfs:8080/tfs/defaultcollection",
[string] $workspaceName = "AutomatedWorkspace",
[string] $workspaceDescription = "AutomatedWorkspace",
[string] $fileName="D:\projects\ProjectMapping.xml",
[bool] $autoDeleteCreate =$true 

Get-ProjectXml $tfs13Url $workspaceName $workspaceDescription $fileName $autoDeleteCreate

Assuming your xml is like: 假设你的xml是这样的:

   <?xml version="1.0"?>
    <Collection Name="DefaultCollection">
      <Root>
        <ServerItem>$/</ServerItem>
        <LocalItem>d:\Src</LocalItem>
      </Root>
      <Project name="ProjectA">
        <Mapping>
          <ServerItem>$/ProjectA/Folder1/BranchDEF</ServerItem>
          <LocalItem>d:\Src\ProjectA\Folder1\BranchDEF\</LocalItem>
        </Mapping>
        <Mapping>
          <ServerItem>$/ProjectA/Folder2\BranchABC</ServerItem>
          <LocalItem>d:\Src\ProjectA\Folder2\BranchABC</LocalItem>
        </Mapping>
     </Project>
     <Project Name="ProjectB">
        <Mapping>
          <ServerItem>$/ProjectB/Folder5\BranchXYZ</ServerItem>
          <LocalItem>d:\Src\ProjectB\Folder5\BranchXYZ</LocalItem>
        </Mapping>
     </Project>
    </Collection> 

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

相关问题 使用powershell从tfs获取项目的最新版本 - Get Latest version of a project from tfs using powershell 使用Powershell从TFS获取最新版本的文件夹 - Get Latest Version of Folder from TFS, using Powershell TFS 2010 Powershell Get-TFSItemHistory 返回最旧版本而不是最新版本 - TFS 2010 Powershell Get-TFSItemHistory returning oldest version and not the latest 如何在PowerShell中编写脚本以运行Microsoft Visual Studio 2010 TFS“获取最新版本”? - How do I write a script in PowerShell to run Microsoft Visual Studio 2010 TFS “Get latest version”? 使用Powershell从tfs文件夹获取最新的检入文件 - Get the latest checkin files from a tfs folder using powershell 使用Powershell创建计划任务时无法传递参数。 我应该将-version作为“ sql server 2016”而不是“ sql” - Unable to pass the parameter while creating the scheduled task using powershell. I should get -version as “sql server 2016” instead of “sql” 如何使用TFS Rest API版本3.2从TFS项目获取测试用例 - How to get test cases from TFS project using TFS rest api version 3.2 C# 与 PowerShell。 如何获取详细的异常信息? - C# vs PowerShell. How to get detailed exception info? Zabbix API 和 Powershell。如何使用主机名获取事件 - Zabbix API with Powershell. How to get events with hostname 如何使用 PowerShell 从 TFS 获取注释? - How to get Annotation from TFS using PowerShell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM