Use NuGet PowerShell commandlets from outside Visual Studio Use NuGet PowerShell commandlets from outside Visual Studio powershell powershell

Use NuGet PowerShell commandlets from outside Visual Studio


The NuGet PowerShell commands rely on being run from within Visual Studio so will not work outside in the normal PowerShell running from the command line.

You can however use migrate.exe which ships with the EntityFramework NuGet package and use that from the command line to update your database.

As a prototype I put together a way to use NuGet PowerShell commands from the normal PowerShell command line using SharpDevelop. Unfortunately at the moment the EntityFramework NuGet package does not work with SharpDevelop.

Another interesting project is StudioShell which provides a new DTE: drive inside Visual Studio but can also be used outside from the command line. I do not believe it supports NuGet PowerShell commands being run from the normal PowerShell command line.


I can find the NuGet.psd1 file at:

C:\Program Files (x86)\Microsoft Visual Studio12.0\Common7\IDE\Extensions\5ttpefif.3mk\Modules\NuGet\NuGet.psd1.

However, when you try to load it:

PS> Import-Module $pathToNuGetPsd1 -Force -NoClobber -Scope GlobalImport-Module : The name of the current Windows PowerShell host is: 'ConsoleHost'.The module 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\5ttpefif.3mk\Modules\NuGet\NuGet.psd1' requires the following WindowsPowerShell host: 'Package Manager Host'.

I think we're out of luck. It has to be run from the Package Manager Host and requires things from Visual Studio as stated by Matt.

To solve my problem I used Chocolatey to install NuGet.CommandLine and then used NuGet.bat to do what I needed. It is a little more work and may not work in all cases depending on what you're trying to do.

Chocolatey: https://github.com/chocolatey/chocolatey/wiki/Installation

NuGet.CommandLine:

PS> cinst NuGet.CommandLine


I'm not terribly familiar with the Visual Studio cmdlets, but you can import a module into your PowerShell session by using Import-Module -Name <ModuleName>. You can list the available (aka. "installed") PowerShell modules by using `Get-Module -ListAvailable'.

My guess would be that the Visual Studio cmdlets are contained with its own PowerShell module, but it's quite possible that it's not "installed" to one of the standard locations in $env:PSModulePath. If this is the case, then you might need to locate the module directory and import either the .psd1 or .psm1 file directly, and pass that into: Import-Module -Name <FullPathToModuleFile>.

As an example of the above, take notice of where the Windows Azure PowerShell module is located: http://trevorsullivan.net/2012/06/07/introducing-microsofts-official-windows-azure-powershell-module/

It's under the Program Files directory, and is not immediately available to PowerShell, unless you import the module from its fully qualified path (the .psd1 module manifest file).

Hope this helps.