question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Visual Studio scaffold with error 'Install the package Microsoft.VisualStudio.Web.CodeGeneration.Design and try again.'

See original GitHub issue

.NET 5, latest release Visual Studio, latest release related issue: #1393

To reproduce the problem. In VS

  • Create a new Razor Pages web app (5.0)
  • Add a model
using System;

namespace ContosoUniversity.Models
{
    public class Student
    {
        public int ID { get; set; }
        public string LastName { get; set; }
        public string FirstMidName { get; set; }
        public DateTime EnrollmentDate { get; set; }
    }
}

Scaffold with model and use + to create a context. The scaffolder adds the following mismatched packages before VS throws an error

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.4">
      <PrivateAssets>all</PrivateAssets>
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
  </ItemGroup>

Expected result: Scaffolded model.

Actual results:


Microsoft Visual Studio

Error

There was an error running the selected code generator:

‘Install the package Microsoft.VisualStudio.Web.CodeGeneration.Design and try again.’

OK

The preceding error results from VS not loading the mismatched NuGet Packages on the first try:

Work around:

Run the scaffolder again. It succeeds the 2nd time.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
cokietechcommented, Nov 17, 2022

I uninstalled and reinstalled Microsoft.VisualStudio.Web.CodeGeneration.Design NuGet package in the package manager. Doing so brought in the CodeGenerator.Design package and added Microsoft.EntityFrameworkCore.Tools. This solved my problem.

Like others, I got the error working through “Get started with Razor Pages in ASP.NET Core” tutorial. The .NET 7 version. I tried several of the above solutions to no avail. I noticed that the project file had a package reference to Microsoft.VisualStudio.Web.CodeGeneration.Design, but it didn’t show up in the project packages. The package showed installed in the Nuget package manager. I uninstalled and reinstalled it in the Nuget package manager. Doing so brought in the CodeGenerator.Design package and added Microsoft.EntityFrameworkCore.Tools. This solved my problem.

2reactions
omadawnxcommented, Mar 6, 2023

in my case, making sure all references are latest version 6 (matches the current net version for now), and installing Microsoft.EntityFrameworkCore.Relational did the trick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Install-Package Microsoft.VisualStudio.Web. ...
The tutorial is suppose to be for .net core 6.0 / the error message indicates there is a version discrepency...it wants to install...
Read more >
Microsoft.VisualStudio.Web.CodeGeneration.Utils not ...
I was able to solve this by doing a NuGet clear/restore and deleting the bin and obj folders from the project directory.
Read more >
c# - I can`t install Package "Microsoft.VisualStudio.Web. ...
Given the error Visual Studio gave you, it seems that you cannot connect to the nuget servers. Do you have a proxy enabled,...
Read more >
I have a problem with Microsoft.VisualStudio.Web. ...
DataAccess and add new Scaffolded item MVC Area, it throws an error. I think there's something wrong with CodeGeneration.Design 6.0.9. I tried ......
Read more >
Microsoft.VisualStudio.Web.CodeGeneration.Design 7.0.9
Version Downloads Last updated 8.0.0‑preview.7.23408.2 887 6 days ago 8.0.0‑preview.6.23360.4 4,597 a month ago 8.0.0‑preview.5.23313.2 4,249 2 months ago
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found