使用PowerShell安装模块

huangapple go评论80阅读模式
英文:

Installing Module using Powershell

问题

你好,以下是您要翻译的内容:

我正在尝试使用PowerShell安装NuGet模块。尽管我以管理员权限运行PowerShell,但出现了以下错误:

NuGet提供程序是必需的以继续
PowerShellGet需要NuGet提供程序版本'2.8.5.201'或更新版本才能与基于NuGet的存储库进行交互。NuGet提供程序必须位于'C:\Program Files\PackageManagement\ProviderAssemblies'或'C:\Users\Admin\AppData\Local\PackageManagement\ProviderAssemblies'中。您也可以通过运行'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'来安装NuGet提供程序。您是否希望PowerShellGet现在安装并导入NuGet提供程序?
[Y] 是 [N] 否 [S] 暂停 [?] 帮助(默认为"Y"):y
警告:无法下载可用提供程序列表。检查您的互联网连接。
PackageManagement\Install-PackageProvider:无法解析包引用'https://onegetcdn.azureedge.net/providers/nuget-2.8.5.208.package.swidtag'。
在C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7468中字符:21

  • ... $null = PackageManagement\Install-PackageProvider -Name
    $script:N ...
+ CategoryInfo          : InvalidData: (https://onegetc...package.swidtag:String) [Install-PackageProvider],异常
+ 
FullyQualifiedErrorId:UnableToResolvePackage,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider

PackageManagement\Import-PackageProvider:未找到指定搜索条件和提供程序名称'NuGet'的匹配项。尝试'Get-PackageProvider -ListAvailable'以查看系统上是否存在该提供程序。
在C:\Program Files\WindowsPowerShell\Modules\PowerShellGet.0.0.1\PSModule.psm1:7474中字符:21
+ ...     $null = PackageManagement\Import-PackageProvider -Name 
$script:Nu ...
+                 
  • CategoryInfo : InvalidData: (NuGet:String) [Import-
    PackageProvider],异常
  • FullyQualifiedErrorId :

NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider

英文:

I am trying to install the NuGet module using Powershell. Though I am running the PowerShell with admin access, I got this error:

    NuGet provider is required to continue
    PowerShellGet requires NuGet provider version '2.8.5.201' or newer to 
    interact with NuGet-based repositories. The NuGet provider must be 
    available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
    'C:\Users\Admin\AppData\Local\PackageManagement\ProviderAssemblies'. You 
    can also install the NuGet provider by running 'Install-PackageProvider 
    -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet 
    to install and import the NuGet provider now?
    [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
    WARNING: Unable to download the list of available providers. Check your 
    internet connection.
    PackageManagement\Install-PackageProvider : Unable to resolve package 
    reference 'https://onegetcdn.azureedge.net/providers/nuget- 
    2.8.5.208.package.swidtag'.
    At C:\Program 
    Files\WindowsPowerShell\Modules\PowerShellGet.0.0.1\PSModule.psm1:7468 
    char:21
    + ...     $null = PackageManagement\Install-PackageProvider -Name 
    $script:N ...
    +                 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: 
    (https://onegetc...package.swidtag:String) [Install-PackageProvider], 
    Exception
    + 

FullyQualifiedErrorId:UnableToResolvePackage,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider

    PackageManagement\Import-PackageProvider: No match was found for the 
    specified search criteria and provider name 'NuGet'. Try 'Get- 
    PackageProvider -ListAvailable' to see if the provider exists on the 
    system.
    At C:\Program 
    Files\WindowsPowerShell\Modules\PowerShellGet.0.0.1\PSModule.psm1:7474 
    char:21
    + ...     $null = PackageManagement\Import-PackageProvider -Name 
    $script:Nu ...
    +                 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (NuGet:String) [Import- 
    PackageProvider], Exception
    + FullyQualifiedErrorId : 

NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider

答案1

得分: 4

尝试按照以下方式安装,如果您在使用企业代理:

[System.Net.WebRequest]::DefaultWebProxy = [System.Net.WebRequest]::GetSystemWebProxy()
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Scope AllUsers

或者... 您可以在使用Install-PackageProvider cmdlet时使用 -Proxy 和 -ProxyCredential 开关。

英文:

Try installing it like this if you're behind a corporate proxy - the first two additional lines will use your current credentials for subsequent cmdlets:

[System.Net.WebRequest]::DefaultWebProxy = [System.Net.WebRequest]::GetSystemWebProxy()
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Scope AllUsers

Or... you can use the -Proxy and -ProxyCredential switches for the Install-PackageProvider cmdlet.

huangapple
  • 本文由 发表于 2020年1月6日 17:45:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609818.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定