Workaround for EF Core 2.1 error: Your startup project ‘project-name’ doesn’t reference Microsoft.EntityFrameworkCore.Design

by

If you’ve followed this blog for a while, you know that I’m obsessed with being able to deploy Entity Framework Core (EF Core) migrations from published (“dotnet publish”) DLLs instead of from the project code.  Why?  Because if you care about DevOps-y things like automated deployments — especially in Visual Studio Team Services — you won’t have the source code around when you’re doing an automated Release.

With EF Core 2.1, I’ve started seeing this error popping up in some unexpected places:

Your startup project ‘project-name’ doesn’t reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.

My DLL most definitely references Microsoft.EntityFrameworkCore.Design. Something has changed with how .NET Core resolves dependencies.  I used to be able to run the following script and have my EF Core migrations just work:

dotnet.exe exec –depsfile .\Benday.Presidents.WebUi.deps.json –additionalprobingpath C:\Users\tfsservice\.nuget\packages “C:\Program Files\dotnet\sdk\2.1.301\DotnetTools\dotnet-ef\2.1.1\tools\netcoreapp2.1\any\tools\netcoreapp2.0\any\ef.dll” database update –assembly .\Benday.Presidents.Api.dll –startup-assembly .\Benday.Presidents.WebUi.dll –project-dir .\ –data-dir .\ –verbose –root-namespace Benday.Presidents.WebUi –context PresidentsDbContext

The Solution

Here’s the fix:

dotnet.exe exec –depsfile .\Benday.Presidents.WebUi.deps.json –additionalprobingpath C:\Users\tfsservice\.nuget\packages –runtimeconfig .\Benday.Presidents.WebUi.runtimeconfig.json “C:\Program Files\dotnet\sdk\2.1.301\DotnetTools\dotnet-ef\2.1.1\tools\netcoreapp2.1\any\tools\netcoreapp2.0\any\ef.dll” database update –assembly .\Benday.Presidents.Api.dll –startup-assembly .\Benday.Presidents.WebUi.dll –project-dir .\ –data-dir .\ –verbose –root-namespace Benday.Presidents.WebUi –context PresidentsDbContext

All you need to do is add the –runtimeconfig arg that points to your *.runtimeconfig.json file and it’ll work.  This arg has to be to the left of the ef.dll arg, too or it won’t work.

I wrestled with this for a couple hours.  I hope this helps and saves you some time.

-Ben

 

3 Responses to "Workaround for EF Core 2.1 error: Your startup project ‘project-name’ doesn’t reference Microsoft.EntityFrameworkCore.Design"
  1. Thanks a lot dude! I’ve been struggling with it all day and still did not figure out why, Should’ve probably just followed your blog.

    One question though. You’re aware that with transition from 2.0 to 2.1 they removed this ef.dll from Microsoft.EntityFrameworkCore.Tools.DotNet and now `dotnet ef` is a part of standard dotnet cli tools.

    Are you maybe planning to update this hack so it wouldn’t work with this hacky dll, but with cli tools instead?

    • Glad this helped you out.

      The “dotnet ef” global tools change in 2.1 that you mentioned is a slightly different problem. The global tools change makes it easier for you to reference the EF Core cli but EF.dll is still required for the tooling to work.

      -Ben

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.