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
Leave a Reply