使用 powershell 从 Tfs 获取工作项存储 [英] Get work item store from Tfs using powershell
问题描述
如何使用 powershell 从 TFS 获取 WorkItemStore?
How do I get a WorkItemStore from TFS using powershell?
我尝试了以下方法:
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 的值.
The above code executes fine and I have a value for $tfs.
然后我这样做:
$wis = $tfs.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
但是 $wis 是空的.如果我这样做,同样的事情:
But $wis is null. Same thing if I do this instead:
$wis = $tfs.TfsTeamProjectCollection.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
此外,如果我这样做,powershell 会说它找不到程序集Microsoft.TeamFoundation.WorkItemTracking.Client",即使它刚刚找到它并在一秒钟前加载它:添加类型 -AssemblyName Microsoft.TeamFoundation.WorkItemTracking.Client
Also, if I do this, powershell says it cannot find assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client' even though it just found it and loaded it a second ago: Add-Type -AssemblyName Microsoft.TeamFoundation.WorkItemTracking.Client
我不明白为什么它找到了程序集然后突然找不到了.
I don't understand why it found the assembly then suddenly can't find it anymore.
我做错了什么?
推荐答案
这样的事情对我有用:
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
}
这篇关于使用 powershell 从 Tfs 获取工作项存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!