gpt4 book ai didi

powershell - 无法添加类型Microsoft.TeamFoundation.Client

转载 作者:行者123 更新时间:2023-12-02 23:54:16 25 4
gpt4 key购买 nike

我试图加载程序集,以便可以从Powershell连接到TFS,但是尝试添加类型时出现错误。 nuget软件包已成功下载,并且我要添加的程序集存在该文件。

我的代码如下

$sourceCodeDirectory = "C:\testing123";

CleanDirectory -directory $sourceCodeDirectory

[System.IO.Directory]::SetCurrentDirectory($sourceCodeDirectory);
$cwd = [System.IO.Directory]::GetCurrentDirectory();

Write-Output("CurrentWorkingDirectory: $cwd");

$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = "$cwd\nuget.exe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
Set-Alias nuget $targetNugetExe -Scope Global -Verbose
nuget install Microsoft.TeamFoundationServer.Client -version '15.112.1' -OutputDirectory $cwd
nuget install Microsoft.TeamFoundationServer.ExtendedClient -version '15.112.1' -OutputDirectory $cwd
$uri = New-Object System.Uri -ArgumentList $TFSCollectionUri

try
{
Write-Output 'Loading TFS Assemblies...'

$assemblyPath = $cwd + "\Microsoft.TeamFoundationServer.ExtendedClient.15.112.1\lib\net45\Microsoft.TeamFoundation.Client.dll";
Write-Output($assemblyPath);

Add-Type -Path $assemblyPath
}
catch
{
$_.LoaderExceptions
{
Write-Error $_.Message
}
}

有以下错误
        Write-Error $_.Message

[ERROR] new-object : Could not load file or assembly
[ERROR] 'Microsoft.VisualStudio.Services.Common, Version=15.0.0.0, Culture=neutral,
[ERROR] PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot
[ERROR] find the file specified.
[ERROR] At C:\Users\user\Documents\Visual Studio 2015\Projects\Build_FormsDesigne
[ERROR] r\Build_FormsDesigner\Build_FormsDesigner.ps1:107 char:23
[ERROR] + ... lProvider = new-object Microsoft.TeamFoundation.Client.UICredentialsP ...
[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] + CategoryInfo : NotSpecified: (:) [New-Object], FileNotFoundExce
[ERROR] ption
[ERROR] + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerS
[ERROR] hell.Commands.NewObjectCommand
[ERROR]
[ERROR] Exception calling "GetTeamProjectCollection" with "2" argument(s): "Could not
[ERROR] load file or assembly 'Microsoft.VisualStudio.Services.Common,
[ERROR] Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of
[ERROR] its dependencies. The system cannot find the file specified."
[ERROR] At C:\Users\user\Documents\Visual Studio 2015\Projects\Build_FormsDesigne
[ERROR] r\Build_FormsDesigner\Build_FormsDesigner.ps1:108 char:1
[ERROR] + $collection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollecti ...
[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
[ERROR] + FullyQualifiedErrorId : FileNotFoundException
[ERROR]
[ERROR] Method invocation failed because [System.String] does not contain a method
[ERROR] named 'Authenticate'.
[ERROR] At C:\Users\user\Documents\Visual Studio 2015\Projects\Build_FormsDesigne
[ERROR] r\Build_FormsDesigner\Build_FormsDesigner.ps1:109 char:1
[ERROR] + $collection.Authenticate()
[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] + CategoryInfo : InvalidOperation: (:) [], RuntimeException
[ERROR] + FullyQualifiedErrorId : MethodNotFound
[ERROR]

同样,当错误出炉时,我尝试加载的DLL仍然有锁,这使我下次运行脚本时无法清除目录。 (我必须关闭Visual Studio并重新打开它才能删除文件锁)

编辑:请澄清一下,当我Nu获取以下程序包时
nuget install Microsoft.TeamFoundationServer.Client -version '15.112.1' -OutputDirectory $cwd

它将所有依赖项拉出,因此它们存在于文件夹中,如下所示

enter image description here

最佳答案

显然,您收到此错误是因为缺少依赖项,因为您的异常正在显示...

无法加载文件或程序集Microsoft.VisualStudio.Services.Common

https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client/

Dependencies  
.NETFramework 4.5
Microsoft.AspNet.WebApi.Client (>= 5.2.2)
Microsoft.TeamFoundation.DistributedTask.Common (= 15.112.1)
Microsoft.VisualStudio.Services.Client (= 15.112.1)
Newtonsoft.Json (>= 8.0.3)

关于powershell - 无法添加类型Microsoft.TeamFoundation.Client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49370247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com