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.

5 Answers 5

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

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.

1
  • 1
    Could you summarize the link in your answer?
    – Scotty H
    Commented Jun 13, 2017 at 21:34
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.

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.

2
  • 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
    Commented Oct 26, 2011 at 15:32
  • You may need to update your powershell (say to Version 5) if your powershell moans about Update-Package being unknown. Commented Mar 17, 2017 at 16:36
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.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.