Reputation: 12538
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.
Upvotes: 25
Views: 16457
Reputation: 2240
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.
Upvotes: 1
Reputation: 889
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.
Upvotes: 11
Reputation: 21490
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.
Upvotes: 2
Reputation: 44798
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
Upvotes: 12
Reputation: 39898
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.
Upvotes: 1