“Build failed” on Database First Scaffold-DbContext

后端 未结 18 1552
醉梦人生
醉梦人生 2020-12-24 04:31

I\'m trying to generate classes from a database (EntityFramework\'s database first approach).

For convenience, I\'m more or less walking along with this tutorial: ht

相关标签:
18条回答
  • 2020-12-24 04:46
    1. Make sure your project is not running
    2. Make sure your project is compiling

    That worked for me.

    0 讨论(0)
  • 2020-12-24 04:48

    I know this is old, but I spent a while trying to figure this out today, so I hope this helps someone.

    I have a .Net Core project but I want to scaffold my files into a .Net Standard class library. DbContext-Scaffold in the package manager console didn't work for me, but dotnet ef dbcontext scaffold in a regular command prompt did.

    I had to install these packages in my class library:

    • Microsoft.EntityFrameworkCore.SqlServer
    • Microsoft.EntityFrameworkCore.Design
    • Microsoft.EntityFrameworkCore.Tools

    I had to have a .Net Core project set as the startup project in my solution and that project had to have a reference to my class library. I think that last part is what I was missing that kept me scratching my head for so long.

    Finally, I cd'd into the class library from a command prompt and ran this:

    dotnet ef dbcontext scaffold "<connection string>" Microsoft.EntityFrameworkCore.SqlServer -o <output folder> -s <relative path to my startup project>
    
    0 讨论(0)
  • 2020-12-24 04:48

    I resolved it with right click on projects and "Unload Project" let only the EF project and run the commands

    0 讨论(0)
  • 2020-12-24 04:49

    For me the issue was that I was trying to set it up in a new blank console project inside of the solution, which had no files, so the scaffolding tried to use this project as a startup project and couldn't find Main. I fixed it by adding a new file with an empty main

    0 讨论(0)
  • 2020-12-24 04:50

    I still had this problem even when I ensured that my project (which had EF Core installed) built correctly. It still failed with the "Build failed." message, which is visible when using the -Verbsose flag.

    I had to do this in my case:

    • Create a throw-away ASP.NET Core web application solution
    • Add the EF Core NuGet package to the solution
    • Add the EF Core Sql Server provider NuGet package (because I'm using SqlServer)
    • Add the EF Core Tools NuGet package
    • Switch -Project in the package manager console command to point to my newly-created (and EF Core-provisioned) project. The last step was just for good measure, since there was only one project in my throw-away solution.

    It seems that this whole process requires an ASP.NET core project (or just a .NET Core project that isn't a class library) somewhere in the solution, presumably set as the solution startup project too.

    0 讨论(0)
  • 2020-12-24 04:52

    I resolved it by stopping my server and then running it again.

    0 讨论(0)
提交回复
热议问题