无法将类型 "System.String" 的值转换为类型 "System.Type"

Cannot convert value of type "System.String" to type "System.Type"

我正在尝试使用 PowerShell 构建一个 tfs 工作站,但我遇到了困难。

在我的代码中有几行

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

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

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

Cannot convert the "Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore" value of type "System.String" to type "System.Type".

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

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

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

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