How can I run Nuget PowerShell cmdlet Install-Package in normal PowerShell session (not inside Visual Studio)?
I would go with *-Package
cmdlets. I've done some automation stuff with NuGet, where I had to choose between NuGet CLI or PowerShell *-Package
cmdlets. Since nuget list --allversion
doesn't work since Feb 2017 (see GitHub ticket). I decided to use the PowerShell cmdlets.
From PowerShell docu:
PS> Install-Package -Name NuGet.Core -Source MyNuGet -Credential Contoso\TestUser
You may have to define the provider name to NuGet
via -ProviderName
:
Specifies one or more package provider names to which to scope your package search. You can get package provider names by running the Get-PackageProvider cmdlet.
...
Accepted values: msi, Programs, msu, Bootstrap, PSModule, nuget, chocolatey
Reason why I wrote this answer though this question is marked as duplicate:
The stackoverflow answer marking this question as duplicate, refers to either use Visual Studios built in management console (which is implemented as seperate Powershell host, and therefore not useable via the standard PowerShell) or via the NuGet CLI tools (which didn't cover all my automation requirements). Using "*-Package` cmdlets are not covered by this answer.
UPDATE 1
Here is an example how to install log4Net
NuGet package:
Install-Package log4net -ProviderName NuGet -Source https://www.nuget.org/api/v2 -Scope CurrentUser -Force
The get more information what is installed in the background you can attach the -Verbose
switch.
As far as I can remember you've to use the v2
API of NuGet.