【问题标题】:Unable to install NuGet package provider in PowerShell Core on Linux无法在 Linux 上的 PowerShell Core 中安装 NuGet 包提供程序
【发布时间】:2020-09-12 03:21:49
【问题描述】:

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

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

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

我也无法使用 PowerShell Core 在 Windows 上安装 NuGet 提供程序,但出现了同样的错误。这只是 PowerShell Core 不支持吗?

【问题讨论】:

    标签: nuget powershell-core


    【解决方案1】:

    我也收到此错误,指定版本(当前为 3.0.0.1)也失败。对我有用的是通过管道将 packageprovider 输入Install-PackageProvider

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

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

    【讨论】:

    • 谢谢,这让我在需要安装软件包的地方完成了一半。一旦我安装了提供程序,我仍然必须注册包源。
    • 感谢您分享这些信息。未来的读者感谢您。
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      将 TLS12 与 Install Nuget 包一起设置对我有用。

      下面是我如何使用命令:

      [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
      Install-PackageProvider -Name NuGet
      

      【讨论】:

        【解决方案4】:

        除了@DougMaurer's answer,我还要配置包源:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-09-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-12-26
          • 2022-06-11
          • 1970-01-01
          • 2022-07-04
          相关资源
          最近更新 更多