1

When using the code generators for scaffolded items in Visual Studio 2019 Version 16.8.5 I get the error message:

*There was an error running the selected code generator: 'Package restore failed. Rolling back package for PROJECT

I've seen so many devs facing the same issue here on Stack Overflow, but the suggested solutions doesn't work for me. Here are an example project from Pluralsight with the issue.

  1. Clone: https://github.com/bjorkblom/.NETCORE
  2. Create a folder named api in OdeToFood/Pages
  3. Right click on the folder and select "Add -> New scaffolded item..."
  4. Choose "API Controller with actions using Entity Framework"
  5. Model Class: Restaurant (OdeToFood.Core)
  6. Data context class: OdeToFoodDbContext (OdeToFood.Data)
  7. Controller name: RestaurantsController
  8. Click "Add" and you'll get the error message.

I've tried to downgrade both the project and entityframework to 3.1 and 2.1. Nothing is working.

bjorkblom
  • 1,849
  • 3
  • 21
  • 31

1 Answers1

6

I had the same problem. What worked for me was using the terminal to create the scaffold

johanjuulj
  • 61
  • 1
  • 2
  • Example use `dotnet aspnet-codegenerator controller -m MyModel -dc MyDbContext -name MyModelssController -async` Worked for EF Core packages 5.0.5 – Nick Pearce Apr 22 '21 at 02:31
  • 1
    Using the terminal solved my issue as well. I needed to scaffold identity and this command worked for me: `dotnet aspnet-codegenerator identity -dc MyApplication.Data.ApplicationDbContext --files "Account.Register;Account.Login;Account.Logout"` – ShawnOrr Aug 13 '21 at 14:31