[英]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.