Always got this error when scaffolding suddenly "there was an error running the selected code generator package restore failed"

Viewed 4071

"there was an error running the selected code generator package restore failed". Rolling back package changes for myproject."

At first I can use scaffolding and works fine. However, yesterday I tried and can't work at all, it's not only on single projects, it's for all projects. I remember there are lot of visual studio updates, I wondered maybe that's the issue. I tried lot of suggestion I can find in internet and nothing works. I think it's not project specific because all my projects can't scaffold. I use postgresql and .NET Core 3.1 . Attached is screenshot of my project dependencies. My specification : visual studio Version 16.7.4 dotnet 3.1.402

This is my dependencies

4 Answers

After stuck for days, I manage to solved it myself. My guess is latest update for Microsoft.EntityFrameworkCore 3.1.8 (I check the logs it's 16 days ago) or latest visual studio update force scaffolding to use 3.1.8. Everytime scaffold using new visual studio update(this is my guess) is installing 3.1.8. I check my .nuget/package in explorer and noticed it. After that I try lot of things because I don't want to upgrade version. I keep the version to 3.1.4 because I use postgre and latest version for postgre library(Npgsql.EntityFrameworkCore.PostgreSQL) is 3.1.4(there is no 3.1.8). It's kind of annoying if library not updated together especially when they have dependencies. However, Since scaffolding use Microsoft.EntityFrameworkCore.SqlServer even though you are not using sqlserver. The solution for this problem is to install latest update of Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore. I don't know how this will affect the code because now I have different version for Microsoft.EntityFrameworkCore and Npgsql.EntityFrameworkCore.PostgreSQL. 

I don't know why I got down votes, this is actually new problem considering update. I have been looking all solution in stackoverflow and other forums and try it but it's not the solution.

I had similar problem so I dig deeper when I tried to add controller scaffolding tried to install Microsoft.EntityFrameworkCore.SqlServer which was already installed so I went back to NuGet packages manager where I observe only one anomaly Microsoft.AspNetCore.SpaServices.Extensions version was different than rest of the packages so I upgraded following to Microsoft.AspNetCore.SpaServices.Extensions version number and problem was solved.

- Microsoft.EntityFrameworkCore
- Microsoft.EntityFrameworkCore.Tools
- Microsoft.EntityFrameworkCore.SqlServer

Rest of the packages were automatically installed during scaffolding process.hope this will help somebody.

These (Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.Tools and Microsoft.EntityFrameworkCore.SqlServer) should be in the same versions

I got around this by rebuilding the solution, click the "rebuild solution" under the build tab. Then the next time I ran the code generator it showed me a different error message. After fixing the error it worked like a charm.

Related