cezarlamann
cezarlamann

Reputation: 1523

Microsoft.VisualStudio.Web.CodeGeneration.Design not being found by the dotnet aspnet-codegenerator tool

I just created an MVC app with dotnet new mvc --name test-project (netcoreapp3.1), without any kind of database access and Identity, which I would like to add by hand for customisation purposes. Then I added some packages in order to use the dotnet aspnet-codegenerator tool. My .csproj looks like this:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>test_project</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.7" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.7" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.7" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.7">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.7">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
  </ItemGroup>
</Project>

As you can see, the Microsoft.VisualStudio.Web.CodeGeneration.Design is the first in the list. However, when I try to run any scaffolder from the dotnet aspnet-codegenerator tool (e.g.: dotnet aspnet-codegenerator identity -h), I get the following message:

No code generators are available in this project.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet package reference.

Even if I specify the .csproj file with the -p flag, I still get the same message. While doing some research, I found this Issue on their repo, but it's a different thing: the OP was trying to add the scaffolder to a .NET Core App 3.0 using the 3.1 scaffolder version.

I'm using .NET 3.1.401 on Xubuntu 20.04.

Any thoughts? Thank you in advance.

EDIT 1 Some people suggested this would be close to what we have here, but the thing is: I know what it does and I actually added the "global tools" suggested in that article. The problem is the aspnet-codegenerator is not detecting that I already have the library it needs to its things, added to the .csproj file.

EDIT 2

Apparently, there's a couple of people facing this issue as well, so, I filed an issue on their repo

Upvotes: 6

Views: 11736

Answers (4)

GetnetA
GetnetA

Reputation: 24

In a case where the installed package version is the last verion of asp.netcore version downgrading is also a solution. E.g. I downgraded from 6.0.16 to 6.0.15 and it works.

Upvotes: 0

dean
dean

Reputation: 355

Here too, mine is not a one-to-one match of @cesarlamann's issue but maybe can help someone else with a similar error.

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

I got the error working through an MS tutorial, "Get started with Razor Pages in ASP.NET Core" - the .NET 7 version. I got the error trying to add a scaffolded Razor Page using Entity Framework (CRUD). Digging around, 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 Nuget package manager showed it installed. I uninstalled and reinstalled it in the Nuget package manager. Doing so brought in the CodeGenerator.Design package and added Microsoft.EntityFrameworkCore.Tools as well. Both packages were added to the Packages folder for the project (expected) and added to the project file. This solved my problem.

Interestingly, I was not able to reproduce the error in a new Razor Pages app.

hth

Upvotes: 0

cezarlamann
cezarlamann

Reputation: 1523

As mentioned by the repository maintainer on the issue I mentioned above in the question, one with this problem should update its packages according to the runtime/target:

Use dotnet tool update dotnet-aspnet-codegenerator -g --version 3.1.5/5.0.2 depending on if you are targeting .netcoreapp3.1 or net5.0. [...] You will also need to update the Microsoft.VisualStudio.Web.CodeGeneration.Design package as well.

Upvotes: 3

Blondu
Blondu

Reputation: 99

This is already a few month old, but I ran into it recently for all my projects.

In case someone else lands on this page, the solution in my case (MAC OS), was to uninstall and reinstall dotnet-aspnet-codegenerator.

Run in terminal:

dotnet tool uninstall --global dotnet-aspnet-codegenerator

dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4

Related topic here

Upvotes: 3

Related Questions