1
votes

I have issues creating a Controller with Scaffolding items. I'm working with Visual Studio 2019 - ASP.NET Core Web Application (with MVC) - ASP.NET Core 3.1

I did the following steps:

  1. I installed from Nuget Packages Manager:
  • Microsoft.EntityFrameworkCore (3.1.3)
  • Microsoft.EntityFrameworkCore.SQLServer (3.1.3)
  • Microsoft.EntityFrameworkCore.Tools (3.1.3)
  1. I made a Model class
  2. I made a DB context class
  3. I added in the ConfigureServices method of Startup class the connection with the DB context and String connection
  4. In appsettings.json I added the String connection to SQLSERVER
  5. right-click on Controllers folder, Add > Controller. Then select ‘MVC Controller with views, using Entity Framework’, selected Model and DB Context but when it's creating the Controller and View the VS showed me an error "Package restore failed. Rolling back package changes for "Name of Project" "

I read other questions related to this, I delete the cache from the Nuget Packages, Rebuild project, change the version of the packages, etc, but the issue still happening.

3

3 Answers

1
votes

Just wanted to add if anyone is seeing this with the Angular SPA template in VS 2019. I tried all the tricks (manual install/update packages, manually clear cache, restart VS, restart computer...), none of them worked.

What finally ended up working was when I randomly decided to look at the csproj after the scaffolding failed and noticed that the Code Generator (latest, at time of writing 3.1.5) set the version of EFCore.SqlServer back to 3.1.13 after I had manually updated to latest (at time of writing 3.1.14).

Basically, the latest version of the code gen is still referencing the older version of the packages so scaffolding never worked

(auto-upgrade and auto-downgrade of packages was failing)

1
votes

I had mostly version 5.0.9 of nuget packages which were last stable at the moment. However New Scaffolded Item wanted 5.0.8 . So I had to downgrade all the nugets to lower version. After that New Scaffolded Item worked out.

0
votes

I had a similar problem Scaffolding a Controller with views, using Entity Framework in VS2019 .NET Core 3.1.

Adding the following packages should solve your problem:

  • Microsoft.EntityFrameworkCore.Design
  • Microsoft.VisualStudio.Web.CodeGeneration.Design

you can do it via:

.NET Core CLI

dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.EntityFrameworkCore.Design

NuGet Package Manager download the package with the appropriate version to your project

Find the packages above with the suited version and add them to your project.