“Build failed” on Database First Scaffold-DbContext

后端 未结 18 1554
醉梦人生
醉梦人生 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 05:08

    Make sure your build works fine.
    Run the scaffold command from the package console, your command should work:

    Scaffold-DbContext 'Data Source=TEST-XY010;Initial Catalog=TESTDB;Trusted_Connection=True' Microsoft.EntityFrameworkCore.SqlServer -Context HOPWAContext -OutputDir TESTModel -Force
    
    0 讨论(0)
  • 2020-12-24 05:10

    Thanks to the above, rebuilding the project solution solved this. Some crucial caveats for me personally were:

    1. Running the dotnet build was not enough (I had asssumed it was)!
    2. In visual studio menu, Build > Build solution (Ctrl + Shift + B)
      • I believe I was simply trying to run the dotnet build command while inside a child project (myProject.data)
      • Rebuilding the parent project (myProject) solution was the key

    I hope that helps someone else who was equally confused!

    0 讨论(0)
  • 2020-12-24 05:11

    If entity-framework returns build failed, most probably you have some kind of error in any of your projects.

    Even if the project you are running the command on, is clean and error-free, other projects in that solution can cause the build failed response.

    Solution

    • Rebuild the whole solution. Most probably you'll find that error in solution-rebuild process.
    • Make sure the project you want to run command on, is selected in Default project drop-down inside Package Manager Console
    • Re-run the command.
    0 讨论(0)
  • 2020-12-24 05:11

    Make sure you have all packages and press ctrl + shift +b to build the solution. It works to me.

    0 讨论(0)
  • 2020-12-24 05:12

    If you use multiple projects in the solution, check the default project in the package manager.

    0 讨论(0)
  • 2020-12-24 05:13

    Manually building the project by pressing Ctrl+Shift+B helped me to see the errors that were causing the build to fail.

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