【问题标题】:Get work item store from Tfs using powershell使用 powershell 从 Tfs 获取工作项存储
【发布时间】:2014-10-15 08:24:38
【问题描述】:

如何使用 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 为空。如果我这样做,同样的事情:

   $wis = $tfs.TfsTeamProjectCollection.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])

另外,如果我这样做,powershell 说它找不到程序集“Microsoft.TeamFoundation.WorkItemTracking.Client”,即使它刚刚找到它并在一秒钟前加载它: Add-Type -AssemblyName Microsoft.TeamFoundation.WorkItemTracking.Client

我不明白为什么它找到了程序集然后突然就找不到了。

我做错了什么?

【问题讨论】:

    标签: powershell tfs


    【解决方案1】:

    这样的东西对我有用:

    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
    }
    

    【讨论】:

    • 对我来说,返回值为空。一切都很好,直到倒数第二行($teamProjectCollection | gm 给了我适当的成员)但是 $ws= 行对我不起作用。 $ws | gm 给出空引用异常(“没有为 get-member cmdlet 指定对象”)。我现在要拔头发了。
    • 尝试将 /DefaultCollection 添加到您的 URI。我正在使用 *.visualstudio.com 并且需要在它工作之前这样做,但我不确定本地服务器是否需要它。
    • 没有帮助。我去server:port/tfs/DefaultCollection 时应该得到什么吗?我得到了 404,但是当我转到 server:port/tfs 时,我得到了我在 DefaultCollection 中访问的最后一个项目的 Web 界面。
    • 我想我的 profile.ps1 中有一些东西干扰了您的代码,也可能干扰了我发布的原始代码。我尝试从 profile.ps1 中删除除您的函数之外的所有内容,现在它可以工作了...谢谢。
    【解决方案2】:

    我在使用 Powershell 尝试获取 WorkItemStore 时也遇到了问题。需要它来克隆 PBI 并克隆任务。找到了这个 .Net 解决方案。像魅力一样工作!实际上必须在 History 空异常周围添加一个 try catch,但在那之后,bam!

    https://github.com/DanielMeixner/WorkItemDeepCopy/

    【讨论】:

    • 请考虑复制对您的答案有用的部分。否则以后用处不大。谢谢
    猜你喜欢
    • 1970-01-01
    • 2018-05-26
    • 2016-04-15
    • 2018-05-24
    • 2016-02-25
    • 2018-09-08
    • 2015-12-30
    • 2014-02-13
    • 1970-01-01
    相关资源
    最近更新 更多