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

4

6

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

Harney answered 16/8, 2020 at 19:10 Comment(4)
did you restored packages before? dotnet restoreChaffee
Does this answer your question? how to use Microsoft.VisualStudio.Web.CodeGeneration?Triboluminescence
@Chaffee yes, I did. Even after doing dotnet clean, dotnet restore and dotnet build it didn't work here, unfortunatelyHarney
@RoarS. Unfortunately not. Please refer to my edit. Thank you for the suggestion anyway.Harney
H
3

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.

Harney answered 12/2, 2021 at 19:53 Comment(0)
J
3

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

Jennette answered 21/11, 2020 at 7:37 Comment(1)
Hi @Blondu. Thank you for the answer. This didn't work. First, because I'm on Linux. Second, If you refer to the issue I created on their repo (link in the question), I already tried doing this.Harney
H
3

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.

Harney answered 12/2, 2021 at 19:53 Comment(0)
S
0

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

Sir answered 17/11, 2022 at 15:15 Comment(0)
E
0

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.

Epicritic answered 30/12, 2023 at 15:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.