Error when trying to add a scaffolded item in Razor Pages

Viewed 1611

I have been trying to add a scaffold item in ASP.NET Core, razor pages using Entity Frameword (CRUD). My current target framework is netcoreapp3.1.

I have the following package versions:

  • Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9"
  • Include="Microsoft.Microsoft.EntityFrameworkCore.Tools" Version="3.1.9"
  • Include="Microsoft.Microsoft.VisualStudio.Web.CodeGeneration.Core" Version="3.1.4"

This is the instructions I am following: https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/intro?view=aspnetcore-5.0&tabs=visual-studio#scaffold-student-pages.

However, when I try adding a scaffold item, the following error occurs:

Error Message

I've tried the following ways to solve the problem:

  1. Clearing nuget cache
  2. Reverting all package versions to 3.1.4
  3. Adding the nuget online reference (https://api.nuget.org/v3/index.json) in package sources.
  4. Re-installing Visual Studio
  5. Clearing ComponentModelCache

Now I'm just wondering if the error is due to using 3.1 framework instead of the latest 5.0.

2 Answers

@Aaron Yong I think I found the problem.

Include="Microsoft.Microsoft.EntityFrameworkCore.Tools" Version="3.1.9"
Include="Microsoft.Microsoft.VisualStudio.Web.CodeGeneration.Core" Version="3.1.4"

You wrote the wrong name for these two packages. They are

Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.9"
Include="Microsoft.VisualStudio.Web.CodeGeneration.Core" Version="3.1.4"

You add one more Microsoft :)

In addition, the version 3.1.9 will be automatically updated to 3.1.10 when add scaffold.

Nothing I found on the internet worked to resolve this. What I did was copy the package references from a working project (all versions are completely mismatched) and it worked. Microsoft's default templates for Razor page scaffolding no longer work. Not sure if they just stopped supporting them forever, or if it's just a bug. Who knows.

Related