Azure DevOps, Scrum, & .NET Software Leadership and Consulting Services

Free course! Predicting the Future, Estimating, and Running Your Projects with Flow Metrics

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


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

 

SUBSCRIBE TO THE BLOG


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

  1. […] To support how all the Entity Framework dependencies are now handled in .NET Core, you’ll need to provide the name of your runtimeconfig.json file for your deployed application.  If you don’t do this, you’ll run into errors where your EF Core dependencies won’t properly resolve. […]

  2. Serhii Prostakov Avatar
    Serhii Prostakov

    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?

    1. Ben Day Avatar

      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

  3. Jason Avatar

    where is this file runtimeconfig.json located in the .net core?

  4. Adel Ahmed Avatar
    Adel Ahmed

    How to Do this please ?

Leave a Reply

Your email address will not be published. Required fields are marked *

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