I am struggling following the tutorial as written. When I try to add a Razor page using the Entity Framework (CRUD), I get an error that says: "There was an error running the selected code generator. Package restore failed. Rolling back package...."
I know this isn't the support forum, but it is really tough working through the tutorials with no information on why the documented step could not complete.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Could you be more specific and give us more info about the issue?
What your dev environment setup looks like (target framework, VS version, SDK version, etc etc)?
I'm guessing it is VS/Nuget-related issue with your setup so try to verify that you have proper nuget sources added.
Also, have you seen this aspnet/Tooling#985?
I followed instructions directly from the tutorial. Running VS 2017 Pro. Entity Framework 6.2 ASP.Net core 2.1. This is a new install on a new Win10 box (first project with VS).
@420tech what version of Visual Studio and .Net core SDK?
dotnet --version
Visual Studio 15.7.4. ASP.Net core 2.1.301.
@420tech are you following the 2.1 version of the tutorial? What step gives you an error?
That's a really old error message we saw in the 2.0 version.
The second step - "Add a model". When I tried to generate a razor page using the "Add Scaffold.." and Razor Pages using Entity Framework (CRUD).
@420tech I assume you are using this sample? https://github.com/aspnet/Docs/tree/master/aspnetcore/tutorials/razor-pages/razor-pages-start/sample/RazorPagesMovie
As @Rick-Anderson said, there was a bug in 2.0 version, and this is the version I see in the sample (https://github.com/aspnet/Docs/blob/master/aspnetcore/tutorials/razor-pages/razor-pages-start/sample/RazorPagesMovie/RazorPagesMovie.csproj)
If so, try to change it to use 2.1. We should probably update the sample code for 2.1 tutorial
I am writing the code myself directly from the tutorial. I am not using any of the code from GitHub. The tutorial I am following can be found here: https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/model?view=aspnetcore-2.1
The step it fails on is the "Add a model". The Add Scaffold part fails on the code generation. Everything I can see tells me I am using 2.1 (e.g. in the Dependencies under NuGet is EntityFramework 6.2, Microsoft.AspNetCore 2.1 and related aspnetcore - all 2.1).
That's odd, could you push your project to the repo so we can clone it and try to repro this on our own?
@420tech try this
dotnet new webapp -o RazorPagesMovie
cd RazorPagesMovie
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet tool install -g dotnet-aspnet-codegenerator --version 2.1.0
// Add movie model to project
// Build run the app.
// From project directory, run in a command window
dotnet aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovie.Data.MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries
dotnet ef migrations add Initial
dotnet ef database update
Thanks @Rick-Anderson! That worked!
I'm not sure if anyone else is having the same issue anymore but a coworker fixed this error for me by building the web application and THEN creating a new razor page.
I have fixed it, by install the package Microsoft.VisualStudio.Web.CodeGeneration.Design from nuget.
In my case, the problem was caused by missing Microsoft.EntityFrameworkCore.Tools NuGet package. Installing it solved the problem.
@Rick-Anderson Thank u sooo much it's solve my problem
Just connect to the Internet to download and install the package.
Most helpful comment
I have fixed it, by install the package Microsoft.VisualStudio.Web.CodeGeneration.Design from nuget.