aspnet-codegenerator: No code generators available, Even after adding Microsoft.VisualStudio.Web.CodeGeneration.Design

Viewed 3610

Unable to generate scaffolding using aspnet-codegenerator, below is what I tried:

  1. Created an ASP.Net RazorPages application using dotnet new webapp

  2. Did a dotnet build

  3. Installed dotnet-aspnet-codegenerator using

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

  4. Ran dotnet aspnet-codegenerator --help

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

  5. Added the package mentioned in step 4 using

    dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design

    Package added is:

    <ItemGroup> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" /> </ItemGroup>

  6. Again ran: dotnet build

    Final-Step

  7. Ran dotnet aspnet-codegenerator --help

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

.Net core installed version: 3.1.401

Os: Ubuntu 20.04

5 Answers

I have same problem when upgrade from .net core 3.1.4 to 5.0.1.

My solution:

  1. update global tools:
  dotnet tool install --global dotnet-aspnet-codegenerator
  dotnet tool update --global dotnet-aspnet-codegenerator
  dotnet tool install --global dotnet-ef
  dotnet tool update --global dotnet-ef
  1. add/update links to packages
  dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Design
  dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
  dotnet add package Microsoft.EntityFrameworkCore.Design
  1. Replace string netcoreapp3.1.4 to net5.0 in .csproj and launch.json files
  2. Clear directories
    • bin
    • obj
  3. Rebuild project
  4. Finally run:
  dotnet aspnet-codegenerator --help

If all fine it will show available generators.

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

The root cause of this problem has been described in this issue as the .NET code expecting a case-insensitive filesystem which fails on a Linux host.

A suggested workaround would be to temporarily mount you ~/.nuget directory on a vfat filesystem.

To do so create a dummy file holding the filesystem

dd if=/dev/zero of=/tmp/mynuget bs=1024k count=2000
mkfs.vfat /tmp/mynuget

and then mount it

sudo mount -o uid=myuser,gid=myuser -t vfat /tmp/mynuget /home/myuser/.nuget

and use it

dotnet restore
dotnet aspnet-codegenerator ...

I test your command,and when I do this dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4,I can get enter image description here

and then Ran dotnet aspnet-codegenerator --help,I get the same message No code generators are available in this project.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet with you, but when I do the following,I can run without the message: enter image description here

I think maybe the package is not added correctly,you can try to remove and add it again.

dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design

I have found the SOLUTION to this issue:

The newest versions are giving some problems, so you will have to downgrade the version of the sdk to the 3.1.3 by writing this command on the terminal:

sudo apt install dotnet-sdk-3.1=3.1.301-1

After that you will need to install the following:

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

After that you will need to add the right Web.CodeGeneration.Design Package by writing this on the terminal:

sudo apt install dotnet-sdk-3.1=3.1.301-1 dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.3

That has worked for me!!

Related