无法在Linux上的PowerShell Core中安装NuGet软件包提供程序

问题描述

我正在尝试在PowerShell 7中的Linux上设置NuGet软件包提供程序,以便可以使用
Install-Package从NuGet gallery获取软件包。但是,当我运行时:

Install-PackageProvider -Name NuGet -Force

我收到以下错误

Install-PackageProvider: No match was found for the specified search criteria for the provider 'NuGet'.
The package provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified
package has the tags.

我做了一些搜索,发现了该网站上的一些问题以及发生此错误的其他问题,有些回答说我需要强制使用TLS 1.2:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

有人说在-requiredVersion上指定Install-PackageSource,有人说使用
-ForceBootstrap,有人说使用-Force。这些工作都不起作用,每次我仍然遇到相同的错误Get-PackageProvider将NuGet列为提供者。

我同样无法使用PowerShell Core在Windows上安装NuGet提供程序。 PowerShell Core只是不支持功能吗?

解决方法

NuGet 位置已更新。您也可以在一行中完成:

Register-PackageSource -Name nuget.org -ProviderName NuGet -Location "https://api.nuget.org/v3/index.json" -Trusted
,

我也收到此错误,并且指定版本(当前为3.0.0.1)也失败。对我有用的是将packageprovider提供给Install-PackageProvider

Get-PackageProvider | where name -eq 'nuget' | Install-PackageProvider

如果要避免对-Force回答是,则可以添加The package(s) come(s) from a package source that is not marked as trusted. Are you sure you want to install software from ''?

,

除了@DougMaurer的答案外,我还必须配置程序包源:

$sourceArgs = @{
  Name = 'nuget.org'
  Location = 'https://www.nuget.org/api/v2'
  ProviderName = 'NuGet'
}
Register-PackageSource @sourceArgs
,

将TLS12与Install Nuget软件包结合使用对我来说很有效。

下面是我使用命令的方式:

[System.Net.ServicePointManager] :: SecurityProtocol = [System.Net.SecurityProtocolType] :: Tls12; Install-PackageProvider-名称NuGet