Doug
Doug

Reputation: 15513

enable-migrations error : project failed to build

Using ASP.NET MVC4 with EF4.3

Running Enable-Migrations from PM Console

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

The project builds (control-shift-B)

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

Upvotes: 10

Views: 38639

Answers (6)

rakshitha bandara
rakshitha bandara

Reputation: 21

In my case I had errors in my project. I have cleared all other errors in my project. Then it works well.

Upvotes: 2

Kaunda
Kaunda

Reputation: 77

In my case there was a message in the Visual Studio output window that made much more sense.

PosmasterDBContext' does not contain a definition for 'Products' and no extension method 'Products' accepting a first argument of type 'PosmasterDBContext' could be found (are you missing a using directive or an assembly reference?)

I knew right away that somewhere in my code, I changed Products to Product

Once I reverted it to Products, the error disappeared.

Upvotes: 0

Daniel Dyson
Daniel Dyson

Reputation: 13230

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.

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

namespace {projectname}.Models

to

namespace {projectname}.Models.Account

Reverting this namespace refactoring fixed the issue.

Sometimes, rarely, ReSharper is not your friend.

Upvotes: 2

Mel
Mel

Reputation: 2385

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 one thing that can cause that error, though.

Upvotes: 6

wayne.blackmon
wayne.blackmon

Reputation: 761

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

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.

Upvotes: 3

Doug
Doug

Reputation: 15513

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.

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

Removing the Configuration class solved my problem.

Upvotes: 2

Related Questions