Scaffold-Dbcontext build failed using EFCore commands

Today in this article, we will cover below aspects,

Issue Description

The EFCore-based application gives scaffold-dbcontext build failed error when scaffolding the entities using the PMC window in Visual Studio IDE,

Error: "Build Failed"
scaffold dbcontext build failed

Resolution

The issue was found to be how the project is being built. This error I was able to reproduce recently using the EFCore version.

This issue could also exist in the lower version of EFCore.

To fix the issue please follow below

Step1:

Before arriving at the fix please make sure to install the EFCore tools properly.

Please see this article for more details: Getting started EFCore in .NET Core

Step2:

Please make sure to set up the project as current in the PMC window as below,

scaffold dbcontext build failed

Step3:

Please make sure each project in your Solution (.sln) is compiling and building successfully.

When you run scaffold-dbcontext commands, the commands basically will run for all the projects.

So your all projects in the project must get compiled and built successfully even if the project is not meant to run for the scaffolding.

I am not sure if this is a limitation or by the design.

Surprisingly the issue was resolved after fixing the build error in the other projects.

scaffold dbcontext build failed

If you still face any issues, Alternately, you can use the EFCore global tool as discussed in the article Scaffolding EFCore DBContext

References:

Did I miss anything else in these resolution steps?

Did the above steps resolve your issue? Please sound off your comments below!

Happy Coding !!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



One thought on “Scaffold-Dbcontext build failed using EFCore commands

Leave a Reply

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