【问题标题】:Cannot convert value of type "System.String" to type "System.Type"无法将“System.String”类型的值转换为“System.Type”类型
【发布时间】:2019-07-15 18:15:09
【问题描述】:

我正在尝试使用 PowerShell 构建一个 tfs 工作站,但我陷入了困境。

在我的代码中是行

$teamProjectCollection = [Microsoft.TeamFoundationClient.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsServer)

$ws = $teamProjectCollection.GetService([type] "Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")

我从this answer 那里得到了关于我最近提出的另一个问题的这些信息。答案解决了我当时遇到的问题,但不幸的是,第二行在尝试将字符串转换为 Type 时出现异常。具体来说,我得到的错误是:

无法将“System.String”类型的“Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore”值转换为“System.Type”类型。

我知道我正在使用的 GetService 函数需要一个 System.Type 参数。我还没有找到严格通过 PowerShell 将 System.String 对象转换为 System.Type 对象的方法。

那么,我该如何解决这个问题或解决这个问题?

【问题讨论】:

  • [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore] | Get-Member 有什么回报吗?
  • 它没有。它得到一个 TypeNotFound 异常。
  • 您是否已将 Microsoft.TeamFoundation.WorkItemTracking.Client.dll 程序集添加到该 PowerShell 会话中?
  • 这就是问题所在。您想将其发布为答案吗?
  • 我贴出来了。谢谢。

标签: powershell tfsbuild


【解决方案1】:

您必须添加一个程序集才能访问[Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore] 类型。假设您位于包含程序集文件的目录中,您可以在当前的 PowerShell 会话中运行以下命令。

Add-Type -Path ".\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-14
    • 1970-01-01
    • 2016-04-09
    • 2014-03-14
    • 2017-11-24
    • 2012-09-07
    相关资源
    最近更新 更多