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

ars1skjm  于 5个月前  发布在  Shell
关注(0)|答案(3)|浏览(90)

我试图安装System.IdentityModel.Tokens.Jwt程序集,但我一直收到nuget错误:
第一个月
当我直接下载.nupkg文件并尝试以这种方式安装时,我得到以下错误:
Install-Package : Unable to find dependent package(s) (Microsoft.IdentityModel.Tokens)
我做错了什么?我通常是一个Linux人,所以我的直觉是我缺乏适当的存储库,但我不知道如何解决这个问题。

cmssoen2

cmssoen21#

这有点难找到,但这里是我的解决方案。如果Get-PackageSource告诉你没有NuGet注册为包源,那么我们首先注册它:
Register-PackageSource -provider NuGet -name nugetRepository -location https://www.nuget.org/api/v2
在那之后,它应该工作。
我有另一个问题,虽然.我确实有NuGet注册,但显然,这个PowerShell插件希望与NuGet的v2 API版本工作,而我有v3注册.有2个解决方案:要么重新注册正确的版本,为此
Unregister-PackageSource -Name nuget.org(首先检查名称),然后使用前面的命令注册正确的版本

在Find(和其他)命令中明确指定正确的API版本:
Find-Package System.IdentityModel.Tokens.Jwt -Source https://www.nuget.org/api/v2。有一个issue on Gihub提供了这个解决方案。

l5tcr1uw

l5tcr1uw2#

这对我很有效:

$_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
}

字符串

stszievb

stszievb3#

在Powershell Core上,您可以将-Source参数中所需的软件包源URL传递给Install-Package命令。
这样你就不必注册一个全局包源。
范例:

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

字符串

相关问题