Install NuGet via PowerShell script

前端 未结 6 467
礼貌的吻别
礼貌的吻别 2020-12-08 00:03

As far as I can tell, NuGet is meant to be installed as a Visual Studio extension:

http://docs.nuget.org/docs/start-here/installing-nuget

相关标签:
6条回答
  • 2020-12-08 00:39

    None of the above solutions worked for me, I found an article that explained the issue. The security protocols on the system were deprecated and therefore displayed an error message that no match was found for the ProviderPackage.

    Here is a the basic steps for upgrading your security protocols:

    Run both cmdlets to set .NET Framework strong cryptography registry keys. After that, restart PowerShell and check if the security protocol TLS 1.2 is added. As of last, install the PowerShellGet module.

    The first cmdlet is to set strong cryptography on 64 bit .Net Framework (version 4 and above).

    [PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
    1
    [PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
    The second cmdlet is to set strong cryptography on 32 bit .Net Framework (version 4 and above).
    
    [PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
    1
    [PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
    Restart Powershell and check for supported security protocols.
    
    [PS] C:\>[Net.ServicePointManager]::SecurityProtocol
    Tls, Tls11, Tls12
    1
    2
    [PS] C:\>[Net.ServicePointManager]::SecurityProtocol
    Tls, Tls11, Tls12
    Run the command Install-Module PowershellGet -Force and press Y to install NuGet provider, follow with Enter.
    
    [PS] C:\>Install-Module PowershellGet -Force
     
    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\administrator.EXOIP\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
    
    [PS] C:\>Install-Module PowershellGet -Force
     
    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\administrator.EXOIP\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
    
    0 讨论(0)
  • 2020-12-08 00:40

    This also seems to do it. PS Example:

    Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
    
    0 讨论(0)
  • Without having Visual Studio, you can grab Nuget from: http://nuget.org/nuget.exe

    For command-line executions using this, check out: http://docs.nuget.org/docs/reference/command-line-reference

    With respect to Powershell, just copy the nuget.exe to the machine. No installation required, just execute it using commands from the above documentation.

    0 讨论(0)
  • 2020-12-08 00:48

    With PowerShell but without the need to create a script:

    Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile Nuget.exe
    
    0 讨论(0)
  • 2020-12-08 00:58
    1. Run Powershell with Admin rights
    2. Type the below PowerShell security protocol command for TLS12:
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    
    0 讨论(0)
  • 2020-12-08 01:04

    Here's a short PowerShell script to do what you probably expect:

    $sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
    $targetNugetExe = "$rootPath\nuget.exe"
    Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
    Set-Alias nuget $targetNugetExe -Scope Global -Verbose
    

    Note that Invoke-WebRequest cmdlet arrived with PowerShell v3.0. This article gives the idea.

    0 讨论(0)
提交回复
热议问题