25

Is there anyway to open NuGet Package Manager console outside Visual Studio ?

My objective is to run some migrations, which I created using EntityFramework.Migrations

Basically I want to run Update-Database –Verbose command in an environment which does not have visual studio, but does have PowerShell 2.0 and NuGet command line tool.

CJBS
  • 15,147
  • 6
  • 86
  • 135
Zasz
  • 12,330
  • 9
  • 43
  • 63

5 Answers5

12

The original posted answer was right at the time, but now (as of 4.3) there is a migrate.exe so you don't need nuget or powershell:

packages\EntityFramework.4.3.1\tools\migrate.exe

See http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-released.aspx

Scott Stafford
  • 43,764
  • 28
  • 129
  • 177
11

The link for migrate.exe info is out-dated. Since this post helped me here is the latest for other folks who stumble upon this:

http://msdn.microsoft.com/en-us/data/jj618307.aspx

Summary: The article gives you instructions on getting migrate.exe installed and using the command line arguments to perform your migration scenario with it. In addition, common issues are identified. Bottom line install EF with nuget and browse to the package's tools folder to find the exe.

Shawn
  • 869
  • 1
  • 9
  • 27
2

Here's a PowerShell function which does the equivalent of update-database in the Package Manager console, from a normal PowerShell window, using EF x.x.x.

I'm using it from the command line as part of a 'full build' process on my dev machine;

function Update-Database($solutionDir, $projectBinDir, $assemblyName, $appConfigFile)
{
    $efMigrateExe = "$solutionDir\packages\EntityFramework.*\tools\migrate.exe"
    Write-Host "Updating Entity Framework Database"
    Write-Host "    Migrate.exe at $efMigrateExe"
    Write-Host "    EF project binary at $projectBinDir"
    Write-Host "    EF config at $appConfigFile"
    . "$efMigrateExe" "$assemblyName" /startupConfigurationFile="$appConfigFile" /startupDirectory="$projectBinDir"
}

The parameters are;

$solutionDir -- the directory where your solution lives; the parent of the packages folder. $projectBinDir -- the <something>\bin\debug directory containing the assembly with your DbContext. $assemblyName -- the name of the assembly file, like MyEfProject.dll appConfigFile -- the name of the app.config or web.config file which contains connection strings etc. Equivalent to using -StartupProjectName in the Package Manager console.

Community
  • 1
  • 1
Steve Cooper
  • 20,542
  • 15
  • 71
  • 88
1

As of today, you can use the dotnet ef command to use all code first command migration.
You need to install it via dotnet tool install --global dotnet-ef before you can use it.

Example:

  • Update-Database

--> dotnet ef database update


  • Add-Migration AddProductReviews

--> dotnet ef migrations add AddProductReviews


  • Remove-Migration

--> dotnet ef migrations remove

Official document can be found here and there.

Matt
  • 25,467
  • 18
  • 120
  • 187
Hayha
  • 2,144
  • 1
  • 15
  • 27
1

If you have a look at the Nuget Faq it states the following:

Can I use NuGet outside of Visual Studio?

You sure can! As discussed in the question on command line tools for NuGet, the primary focus of NuGet is Visual Studio, but the core NuGet API has no dependencies on Visual Studio. There are multiple NuGet clients that work completely outside of Visual Studio:

SharpDevelop Alpha. (See a demo of this in Phil Haack's MvcConf talk.)

ASP.NET Web Pages in WebMatrix. (See a demo of this in Phil Haack's talk.)

NuGet.exe

But for using the code first migrations outside visual studio the release notes say the following:

No outside-of-Visual-Studio experience. Alpha 2 only includes the Visual Studio integrated experience. We also plan to deliver a command line tool and an MSDeploy provider for Code First Migrations.

Community
  • 1
  • 1
Wouter de Kort
  • 39,090
  • 12
  • 84
  • 103
  • 3
    Nuget command line tool does not have a command that does `Update-Database –Verbose` - My question is how to run powershell scripts like that outside visual studio, outside the package manager console! Looking for something like `nuget -custom "Update-Database –Verbose"`! – Zasz Oct 26 '11 at 15:32
  • @Zasz: Did you read the answer? Did you read release notes for the package? Alpha version is currently targeted only to VS experience = no out of VS support is provided. – Ladislav Mrnka Oct 26 '11 at 18:20
  • You may need to update your powershell (say to Version 5) if your powershell moans about `Update-Package` being unknown. – andrew pate Mar 17 '17 at 16:36