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.

Cannot generate controller from cli

See original GitHub issue

When running dotnet aspnet-codegenerator controller -name AuthorController -async -api -m Author -dc MyDbContext -outDir Controller

I get the following error

Building project ...
Finding the generator 'controller'...
No code generators found with the name 'controller'
   at Microsoft.VisualStudio.Web.CodeGeneration.CodeGeneratorsLocator.GetCodeGenerator(String codeGeneratorName)
   at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:04.23

Steps to reproduce:

run dotnet aspnet-codegenerator controller -name AuthorController -async -api -m Author -dc MyDbContext -outDir Controller

Here is my csproj

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <LangVersion>latest</LangVersion>
    <Nullable>enable</Nullable>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <GenerateDocumentationFile>false</GenerateDocumentationFile>
    <UserSecretsId>xxx</UserSecretsId>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
  </ItemGroup>

</Project>

Here is my dotnet-tools.json

{
  "version": 1,
  "isRoot": true,
  "tools": {
    "dotnet-ef": {
      "version": "3.1.4",
      "commands": [
        "dotnet-ef"
      ]
    },
    "dotnet-aspnet-codegenerator": {
      "version": "3.1.3",
      "commands": [
        "dotnet-aspnet-codegenerator"
      ]
    }
  }
}

Expected behavior:

Controller to be created

Actual behavior:

Failure

Building project ...
Finding the generator 'controller'...
No code generators found with the name 'controller'
   at Microsoft.VisualStudio.Web.CodeGeneration.CodeGeneratorsLocator.GetCodeGenerator(String codeGeneratorName)
   at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:04.23

Additional information about the project being scaffolded, such as:

Target framework(s):

netcoreapp3.1

Package version of Microsoft.AspNetCore.App or Microsoft.AspNetCore.All (if applicable):

Not manually selected

Package version of Microsoft.VisualStudio.Web.CodeGeneration.Design - this may be added to your project by scaffolding:

3.1.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ChristianFigueredocommented, Jan 23, 2021

I fixed it updating the codegenator package:

  • uninstall codegenerator:

dotnet tool uninstall --global dotnet-aspnet-codegenerator

  • install codegenerator (use your sdk version)

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

  • Restore dotnet restore
1reaction
TB-Developmentcommented, Dec 10, 2020
  1. Add a global.json to specify your sdk version.

dotnet new globaljson --sdk-version 3.1.300

  1. Change your target framework in csproj file to (specify .NET version)
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  1. Remove the newest version of CodeGeneration installed by default (without version number)

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

  1. Add a different, stable version back

dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design -v 3.1.0

dotnet restore dotnet build

You can see your SDKs and runtimes installed with.

dotnet info

you can see your packages with

dotnet list package

As for why this happened. No idea, Just downgrading my SDK, .NET core env and the package version worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Not able to generate controller and views from Entity ...
NET Core 3.1 I am looking for a way to generate controllers and CRUD views from the command line in Windows from my...
Read more >
dotnet aspnet-codegenerator command
Generate controller with read/write actions without a model. Use the -h switch for help on the aspnet-codegenerator controller command: .NET CLI
Read more >
Part 4, add a model to an ASP.NET Core MVC app
MvcMovieContext is generated. Select Add. In the Database provider drop down, select SQL Server. Views and Controller name: Keep the default.
Read more >
The Rails Command Line
The Rails Command LineAfter reading this guide, you will know: How to create a Rails application. How to generate models, controllers, database migrations, ......
Read more >
Implementing the IBM SAN Volume Controller with IBM Spectrum ...
You cannot create a child pool for a Data Reduction Pool (DRP) ... When the user logs on to the management GUI or...
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