asp.net-mvc 启用迁移错误:项目无法构建

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11918401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 02:09:39  来源:igfitidea点击:

enable-migrations error : project failed to build

asp.net-mvcentity-framework

提问by Doug

Using ASP.NET MVC4 with EF4.3

在 EF4.3 中使用 ASP.NET MVC4

Running Enable-Migrationsfrom PM Console

Enable-Migrations从 PM 控制台运行

System.Management.Automation.RuntimeException: The project 'MyProj' failed to build. The project 'MyProj' failed to build.

System.Management.Automation.RuntimeException: 项目“MyProj”无法构建。项目“MyProj”未能构建。

The project builds (control-shift-B)

项目构建(control-shift-B)

Is there any way to get more detail on this error to diagnose?

有没有办法获得有关此错误的更多详细信息以进行诊断?

采纳答案by Doug

Turns out I had run this earlier, on a project where there was no dbContext. This created a migrations Configuration class that said "fill in the name of the class", which was failing to build.

原来我之前在一个没有 dbContext 的项目上运行过这个。这创建了一个迁移配置类,上面写着“填写类的名称”,它无法构建。

This was causing one of my projects to silently fail to compile.

这导致我的一个项目默默地无法编译。

Removing the Configuration class solved my problem.

删除 Configuration 类解决了我的问题。

回答by wayne.blackmon

Executing "Enable-Migrations" from the package manager console requires a reference to a specific DbContext. For example

从包管理器控制台执行“Enable-Migrations”需要对特定 DbContext 的引用。例如

PM> Enable-Migrations -ContextTypeName myMvcApp.Web.Infrastructure.ContextDb

You do not need to install a 3rd party assembly or any other assembly other than the EntityFramework 4.3+ (the command above is for EF 5.0. This is not a well documented but essential feature of the EF.

您不需要安装第 3 方程序集或除 EntityFramework 4.3+ 之外的任何其他程序集(上述命令适用于 EF 5.0。这不是 EF 的一个详细记录但必不可少的功能。

回答by Mel

This can also happen if you are building a 64-bit application. Switch to "Any CPU", at least temporarily while building the migrations, and the problem may go away. This is just onething that can cause that error, though.

如果您正在构建 64 位应用程序,也会发生这种情况。至少在构建迁移时暂时切换到“任何 CPU”,问题可能会消失。不过,这只是可能导致该错误的件事。

回答by Daniel Dyson

Let's be clear. This error is a confusing one because the message suggests that the project won't build whereas it clearly does compile in Visual Studio.

让我们说清楚。此错误是一个令人困惑的错误,因为该消息表明该项目不会生成,而它显然会在 Visual Studio 中编译。

It happened to me after refactoring namespaces for ApplicationDbContext and other security classes to match the folder structure from

在重构 ApplicationDbContext 和其他安全类的命名空间以匹配来自

namespace {projectname}.Models

to

namespace {projectname}.Models.Account

Reverting this namespace refactoring fixed the issue.

恢复这个命名空间重构修复了这个问题。

Sometimes, rarely, ReSharper is not your friend.

有时,很少,ReSharper 不是您的朋友。