如何使用PowerShell从TFS获取WorkItemStore?
我尝试过以下方法:
function get-tfs {
param(
[string] $ServerName = "http://MyServer:8080/tfs"
)
begin{}
process
{
[psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
return $tfs
}
end{}
}
[Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.WorkItemTracking.Client.dll")
上面的代码执行正常,我有$ tfs的值。
然后我这样做:
$wis = $tfs.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
但$ wis为null。如果我改为这样做:
$wis = $tfs.TfsTeamProjectCollection.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
另外,如果我这样做,powershell说它无法找到程序集' Microsoft.TeamFoundation.WorkItemTracking.Client'即使它刚刚发现它并在一秒前加载它: Add-Type -AssemblyName Microsoft.TeamFoundation.WorkItemTracking.Client
我不明白为什么它发现装配然后突然发现它了。
我做错了什么?
答案 0 :(得分:4)
这样的事情对我有用:
function get-tfs
{
param([string] $ServerName = "http://myserver:8080/tfs")
$binpath = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0"
Add-Type -path "$binpath\Microsoft.TeamFoundation.Client.dll"
Add-Type -Path "$binpath\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
$creds = New-Object Microsoft.TeamFoundation.Client.UICredentialsProvider
$teamProjectCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection $ServerName,$creds
$ws = $teamProjectCollection.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
return $ws
}
答案 1 :(得分:0)
我在使用Powershell尝试获取WorkItemStore时遇到了问题。需要克隆PBI并克隆任务。发现这个.Net soln。像魅力一样工作!实际上不得不在History null异常周围添加一个try catch,但之后,bam!