在 Visual Studio 外部使用 NuGet 包管理器控制台来运行实体框架迁移
是否有办法在 Visual Studio 之外打开 NuGet 包管理器控制台?
我的目标是运行一些迁移,这些迁移是我使用 EntityFramework.Migrations
基本上我想在没有视觉效果的环境中运行 Update-Database –Verbose
命令studio,但确实有 PowerShell 2.0 和 NuGet 命令行工具。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
最初发布的答案当时是正确的,但现在(截至 4.3)有一个 migrate.exe,因此您不需要 nuget 或 powershell:
请参阅 http://blogs.msdn.com/b/adonet/存档/2012/02/09/ef-4-3-released.aspx
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:
See http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-released.aspx
migrate.exe 信息的链接已过时。由于这篇文章对我有帮助,因此对于其他偶然发现此问题的人来说是最新的:
http: //msdn.microsoft.com/en-us/data/jj618307.aspx
摘要:本文为您提供有关安装 migrate.exe 并使用命令行参数执行的说明您的迁移场景。此外,还确定了常见问题。底线是使用 nuget 安装 EF 并浏览到包的工具文件夹以查找 exe。
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.
这是一个 PowerShell 函数,它在正常的 PowerShell 窗口中使用 EF xxx 在程序包管理器控制台中执行相当于
update-database
的操作,我从命令行使用它作为“完整构建”的一部分' 在我的开发机器上进行处理;
参数是;
$solutionDir
-- 解决方案所在的目录;packages
文件夹的父级。$projectBinDir
-- 包含带有DbContext
的程序集的\bin\debug
目录。$assembleName
-- 程序集文件的名称,例如MyEfProject.dll
appConfigFile
-- 包含连接字符串等的app.config
或web.config
文件的名称。相当于使用-StartupProjectName
在包管理器控制台中。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;
The parameters are;
$solutionDir
-- the directory where your solution lives; the parent of thepackages
folder.$projectBinDir
-- the<something>\bin\debug
directory containing the assembly with yourDbContext
.$assemblyName
-- the name of the assembly file, likeMyEfProject.dll
appConfigFile
-- the name of theapp.config
orweb.config
file which contains connection strings etc. Equivalent to using-StartupProjectName
in the Package Manager console.如果您查看 Nuget 常见问题解答,它会说明以下内容:
但是,要在 Visual Studio 之外使用代码优先迁移,发行说明内容如下:
If you have a look at the Nuget Faq it states the following:
But for using the code first migrations outside visual studio the release notes say the following:
从今天开始,您可以使用
dotnet ef
命令来使用所有代码优先命令迁移。您需要通过
dotnet tool install --global dotnet-ef
安装它才能使用它。示例:
更新数据库
-->
dotnet ef 数据库更新
Add-Migration AddProductReviews
-->
dotnet ef migrations add AddProductReviews
Remove-Migration
-->
dotnet ef 迁移删除
官方文档可以在这里找到和那里。
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.