Code First Migrations StartUp Project Does Not Reference The Project Contains Migrations

Could not load assembly ‘CFMigrationsSyntax.DataLayer’. (If you are using Code First Migrations inside Visual Studio this can happen if the startUp project for your solution does not reference the project that contains your migrations. You can either change the startUp project for your solution or use the -StartUpProjectName parameter.)

Depend on your solution and projects setup in Visual Studio, sometime Entity Framework Code First commands don’t run as expected.

By default, when Code First migration commands run, it will pick the default project set on your Package Manager Console:


But most of the time, we have separate projects in Visual Studio solutions for presentation, business and data layers. EF Code First migration is enabled on the project where your EF Context lives, data layer, while the startup project for the solution is the presentation layer’s project. And since the startup project doesn’t have reference to data layer (where EF is), Package Manager Console will always throw error when running Code First migration commands.

Here’s my typical projects setup:


MainConsole is the presentation and reference to the business layer, CFMigrationsSyntax.BusinessLayer project. In turn, CFMigrationsSyntax.BusinessLayer reference to the data layer, CFMigrationsSyntax.DataLayer.

To run EF Code First commands againts the data layer project, CFMigrationsSyntax.DataLayer, first change the default project in Package Manager Console to your EF project and then add the following parameter to the Code First migration commands:

-StartUpProjectName <EF_project>

In my case:

PM> Enable-Migrations -StartUpProjectName CFMigrationsSyntax.DataLayer

1 thought on “Code First Migrations StartUp Project Does Not Reference The Project Contains Migrations”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s