PowerShell NuGet - “未找到指定搜索条件的匹配项”、“无法找到依赖包”等

问题描述 投票:0回答:4

我试图安装程序集 System.IdentityModel.Tokens.Jwt,但我不断收到 nuget 错误:

find-package : No match was found for the specified search criteria and package name
'System.IdentityModel.Tokens.Jwt'. Try Get-PackageSource to see all available registered package sources.

当我直接下载 .nupkg 文件并尝试以这种方式安装时,出现以下错误:

Install-Package : Unable to find dependent package(s) (Microsoft.IdentityModel.Tokens)

我做错了什么?我通常是一个 Linux 人,所以我的直觉是我缺乏合适的存储库,但我不知道如何解决这个问题。

powershell package nuget jwt
4个回答
20
投票

这有点难找到,但这是我的解决方案。如果

Get-PackageSource
告诉您没有 NuGet 注册为包源,那么我们首先注册它:

Register-PackageSource -provider NuGet -name nugetRepository -location https://www.nuget.org/api/v2

之后应该可以工作了。

不过我还有另一个问题。我确实注册了 NuGet,但显然,这个 PowerShell cmdlet 期望与 NuGet 的 v2 API 版本一起使用,而我注册了 v3。有 2 个解决方案:要么重新注册正确的版本,为此

Unregister-PackageSource -Name nuget.org
(先检查名称)然后使用之前的命令注册正确的版本

在查找(和其他)命令中明确指定正确的 API 版本:

Find-Package System.IdentityModel.Tokens.Jwt -Source https://www.nuget.org/api/v2
。 Gihub 上有一个 issue 提供了此解决方案。


1
投票
这对我有用:

$_nugetUrl = "https://api.nuget.org/v3/index.json" $packageSources = Get-PackageSource if(@($packageSources).Where{$_.location -eq $_nugetUrl}.count -eq 0) { Register-PackageSource -Name MyNuGet -Location $_nugetUrl -ProviderName NuGet }
    

0
投票
在 pwsh(powershell 核心)上,您可以将

-Source

 参数中必要的包源 URL 传递给 
Install-Package
 命令。

这样你就不必注册全局包源了。

示例:

Install-Package -Force Microsoft.Azure.Kusto.Tools.NETCore ` -Destination "/tmp/mypackages" ` -Source "https://api.nuget.org/v3/index.json"
    

0
投票
Install-Package:未找到指定搜索条件和包名称“Swashbuckle.AspNetCore”的匹配项。尝试 Get-PackageSource 查看全部 可用的已注册包源。 在行:1 字符:1

    安装包 Swashbuckle.AspNetCore
  • + CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
    
    
© www.soinside.com 2019 - 2024. All rights reserved.