Angular CLI-based template: Follow the BuildWebHost convention for better compatibility with EF Design Tools #270

Closed
opened 2025-08-09 17:15:39 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @andrewjsaid on 12/12/2017

This issue is based on my comment in #1288

I may have found a regression with the newest template Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0-preview1-final.

In older templates, the Program class had a method IWebHost BuildWebHost which has been replaced with IWebHostBuilder CreateWebHostBuilder.

The problem occurs when attempting to run EF migrations dotnet ef migrations add Migration1. The new template causes the following error to appear

Unable to create an object of type 'DbContext'. Add an implementation of 'IDesignTimeDbContextFactory<DbContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.

Some digging about shows that BuildWebHost is a convention expected by Entity Framework Core Design Tools. see cda9ec6fe4/shared/Microsoft.AspNetCore.Hosting.WebHostBuilderFactory.Sources/WebHostFactoryResolver.cs

There is a solution - which is to expose the IDesignTimeDbContextFactory<DbContext> as suggested in the error message - but it would be easier for everybody if EF Design tools work out of the box.

*Originally created by @andrewjsaid on 12/12/2017* This issue is based on my comment in #1288 I may have found a regression with the newest template `Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0-preview1-final`. In older templates, the `Program` class had a method `IWebHost BuildWebHost` which has been replaced with `IWebHostBuilder CreateWebHostBuilder`. The problem occurs when attempting to run EF migrations `dotnet ef migrations add Migration1`. The new template causes the following error to appear Unable to create an object of type 'DbContext'. Add an implementation of 'IDesignTimeDbContextFactory<DbContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time. Some digging about shows that BuildWebHost is a convention expected by Entity Framework Core Design Tools. see https://github.com/aspnet/Hosting/blob/cda9ec6fe416eaa4fdc8f72276c7b16941d9761c/shared/Microsoft.AspNetCore.Hosting.WebHostBuilderFactory.Sources/WebHostFactoryResolver.cs There is a solution - which is to expose the `IDesignTimeDbContextFactory<DbContext>` as suggested in the error message - but it would be easier for everybody if EF Design tools work out of the box.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#270
No description provided.