【问题标题】:Cannot find [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory] even after using Add-Type即使在使用 Add-Type 后也找不到 [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]
【发布时间】:2019-11-28 18:24:44
【问题描述】:

我正在尝试为可能没有管理员权限的用户自动将 tfs 集合映射到本地工作区。

目前,我正在尝试使用

$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationFactory]::GetServer($tfsServer)

获取 TFS 服务器。但是,这行代码会导致错误提示

找不到类型 [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]

我已包含以下行:

Add-Type -Path "$path.Microsoft.TeamFoundation.Client.dll"

在脚本的前面。

我早些时候发布了this question,但我仍在为该问题将相关的 DLL 放入 GAC。我不再这样做了,因为对 GAC 的操作通常需要管理员权限,并且我不能保证我的脚本的用户将拥有这些权限。

既然我决定不将 DLL 添加到 GAC,那么现在正在运行的代码就会失败。

有没有办法在不使用 GAC 或其他任何需要管理员权限的情况下获取 TFS 服务器,如果是,我该怎么做?

【问题讨论】:

  • 您的Add-Type 行是错字吗?我认为应该是"$path\Microsoft.Team 而不是"$path.Microsoft.Team

标签: powershell tfs


【解决方案1】:

修改代码如下:

    $TfsAssembliesPath="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.ServiceBus.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.VisualStudio.Services.Common.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.VisualStudio.Services.WebApi.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.VisualStudio.Services.Client.Interactive.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Core.WebApi.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Common.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Client.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.TestManagement.Common.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.ProjectManagement.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Build.Client.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Build.Common.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Git.Client.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.SourceControl.WebApi.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.Client.QueryLanguage.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.Common.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.TestManagement.Client.dll"
[string]$tfsCollectionUrl="TFS collection URL"
    [string]$tfsTeamProjectName="team project"

    $teamProjectCollection=[Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsCollectionUrl)
    $ws = $teamProjectCollection.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
    $proj = $ws.Projects[$tfsTeamProjectName]

    $wit = $proj.WorkItemTypes["Task"]

    #Create a new work item of that type
    $workitem = $wit.NewWorkItem()

    $workItem.Title = "Sample Task Title 3"
    $workItem.Description = "Sample Description"
    $workitem.AreaPath = $tfsTeamProjectName
    $workitem.IterationPath = $tfsTeamProjectName

    $workItem.Save()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-17
    • 2013-10-24
    • 1970-01-01
    相关资源
    最近更新 更多