有谁知道如何编写PowerShell脚本来自动化Team Foundation Server的“获取最新版本”功能?
我尝试了几个例子,但都没有。
到目前为止,这是我的代码:
#Load Reference Assemblies
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Common")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
Function Get-TFSLatestFromVersionControls
{
param
(
#FQDN to SCCM Server
[Parameter(Mandatory=$true)][string]$YourServerPath = "$/DEV",
[Parameter(Mandatory=$true)][string]$YourLocalPath = "C:\Project\DEV",
[Parameter(Mandatory=$false)][string]$tfsCollectionUrl = "http://10.0.10.200:8080/tfs/collection"
)
#Delete the old local copy
if((Test-Path -Path ($YourLocalPath)) -eq 1 )
{
Remove-Item -Path $YourLocalPath -Recurse
New-Item -Path $YourLocalPath -Type directory
Read-Host -Prompt "Delete the old local copy"
}
#Get Team Project Collection
$teamProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsCollectionUrl)
#enter a path to your tfs server
$tfsServer = $tfsCollectionUrl
# get an instance of TfsTeamProjectCollection
$tfs=get-tfsserver $tfsServer
# get an instance of VersionControlServer
$vCS = $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
$TeamProject = $YourServerPath.Remove(0,2)
$tfsProject = $vcs.GetTeamProject($TeamProject)
$workspace = $vcs.GetWorkspace($YourLocalPath)
if($workspace -eq $null)
{
$vcs.DeleteWorkspace("TFS-"+$env:COMPUTERNAME,$env:USERNAME)
$workspace = $vcs.CreateWorkspace("TFS-"+$env:COMPUTERNAME, $env:USERNAME)
Read-Host -Prompt "Delete the old workspace"
}
$workspace.Map($YourServerPath, $YourLocalPath)
$workspace.Get([Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest ,[Microsoft.TeamFoundation.VersionControl.Client.GetOptions]::Overwrite)
Read-Host -Prompt "Get Latest"
}
答案 0 :(得分:0)
实现这一目标的最简单方法是安装Patrick提到的TFS PowerTools,然后您只需使用“Update-TfsWorkspace
”命令获取最新版本。
如果您想通过TFS API获取最新信息,请参阅以下代码了解详情:
$uri = "http://tfsurl:8080/tfs/collectionname/";
$workspacename = "workspacename"
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($uri)
$vcs = $tfs.GetService("Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer")
$workspaces = $vcs.QueryWorkspaces($workspacename,"","")
$workspace = $workspaces | Select-Object -First 1
$workspace.Get();