Install NuGet via PowerShell script
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.
Solution 1:
- Run Powershell with Admin rights
- Type the below PowerShell security protocol command for TLS12:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Solution 2:
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.