74

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

But what if I need NuGet on a machine that doesn't have VS installed?

Specifically, I would like to install NuGet with a PowerShell script.

2
  • NuGet is standalone program now and should not be considered as any kind of extension. Commented Jul 10, 2020 at 13:00
  • Today, the question is why you need it at all? I was facing this, when trying to install and use the BurntToast package to send (Windows) toast notifications from the old powershell.exe in MSYS. Then it asked all kinds of weird things about installing NuGet and having to use special permissions. Instead I just added the new pwsh.exe to PATH, and it just worked, without any NuGet. I.e. make sure you use the latest powershell 7 "core". Commented Oct 14 at 22:34

6 Answers 6

134
  1. Run Powershell with Admin rights
  2. Type the below PowerShell security protocol command for TLS12:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Sign up to request clarification or add additional context in comments.

3 Comments

Error: Cannot set property. Property setting is supported only on core types in this language mode.
@HackSlash turn off powershell constrained-language mode. it doesn't make the system any more secure, it just makes it harder to get anything done.
i had to set both Tls versions as in [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls11,Tls12' to make it work on windows server 2016
61

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.

2 Comments

I updeated script to grab the latest NuGet.exe, here: https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
Invoke-WebRequest should get -UseBasicParsing in PS older that 6.0.
27

This also seems to do it. PS Example:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

4 Comments

But how to you get a newer version than 2?
Note: around the 3rd April 2020 the minimum TLS version was raised on the provider lookup site, if your machine has not been set by policy, you can set using [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls11,Tls12'
Use Install-PackageProvider -Name NuGet -Scope CurrentUser to use it without admin rights. That command will not work on Powershell Core.
@JulesClements thanks, you saved me a couple of hours
10

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.

4 Comments

Thanks for the response. Do you know if links are available for specific versions of NuGet.exe ?
Hmm, I do not know where to find commands for an associated version of nuget. But I guess if you need to know what version of nuget.exe you have, just type "nuget help". This can help assist in searching further for command compatibilities.
Worth noting that the version at http://nuget.org/nuget.exe is old compared to the one at https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
Just under three years later, worth noting is also https://www.nuget.org/downloads
6

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

Comments

4

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

1 Comment

I never got asked for NuGet to be installed. Perhaps because I already have nuget.exe in the directory running the above PS lines?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.