在 Visual Studio 外部使用 NuGet 包管理器控制台来运行实体框架迁移

发布于 2024-12-12 07:07:51 字数 411 浏览 0 评论 0原文

是否有办法在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

巴黎盛开的樱花 2024-12-19 07:07:51

最初发布的答案当时是正确的,但现在(截至 4.3)有一个 migrate.exe,因此您不需要 nuget 或 powershell:

packages\EntityFramework.4.3.1\tools\migrate.exe

请参阅 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:

packages\EntityFramework.4.3.1\tools\migrate.exe

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

一梦浮鱼 2024-12-19 07:07:51

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.

赠意 2024-12-19 07:07:51

这是一个 PowerShell 函数,它在正常的 PowerShell 窗口中使用 EF xxx 在程序包管理器控制台中执行相当于 update-database 的操作,

我从命令行使用它作为“完整构建”的一部分' 在我的开发机器上进行处理;

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"
}

参数是;

$solutionDir -- 解决方案所在的目录; packages 文件夹的父级。
$projectBinDir -- 包含带有 DbContext 的程序集的 \bin\debug 目录。
$assembleName -- 程序集文件的名称,例如 MyEfProject.dll
appConfigFile -- 包含连接字符串等的 app.configweb.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;

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.

烈酒灼喉 2024-12-19 07:07:51

如果您查看 Nuget 常见问题解答,它会说明以下内容:

我可以在 Visual Studio 之外使用 NuGet 吗?

你一定可以!正如所讨论的
在有关 NuGet 命令行工具的问题中,主要关注点是
NuGet 是 Visual Studio,但核心 NuGet API 不依赖于
视觉工作室。有多个 NuGet 客户端可以完全运行
Visual Studio 之外:

SharpDevelop Alpha。 (请参阅 Phil Haack 的 MvcConf 演讲中的演示。)

WebMatrix 中的 ASP.NET 网页。 (请参阅 Phil Haack 演讲中的演示。)

NuGet.exe

但是,要在 Visual Studio 之外使用代码优先迁移,发行说明内容如下:

没有 Visual Studio 之外的经验。 Alpha 2 仅包括
Visual Studio 集成体验。我们还计划发出命令
line 工具和用于 Code First 迁移的 MSDeploy 提供程序。

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.

涫野音 2024-12-19 07:07:51

从今天开始,您可以使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文