Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot generate controller from cli #1347

Closed
AceHack opened this issue Jun 7, 2020 · 18 comments
Closed

Cannot generate controller from cli #1347

AceHack opened this issue Jun 7, 2020 · 18 comments

Comments

@AceHack
Copy link

AceHack commented Jun 7, 2020

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

@AceHack
Copy link
Author

AceHack commented Jun 7, 2020

The problem appears to be caused by installing the latest dotnet core SDK 3.1.400-preview-015151 that comes with the latest VS 2019 16.7 Preview 2. Rolling back to SDK 3.1.300 appears to have fixed the issue.

@bravecobra
Copy link

I seem to have hit the same problem.

@Rick-Anderson
Copy link
Contributor

@AceHack this doesn't repo with the current released 3.1 SDK. Can you close this issue?

@AceHack
Copy link
Author

AceHack commented Jun 10, 2020

Where is the place to file bugs on preview releases?

@Rick-Anderson
Copy link
Contributor

Where is the place to file bugs on preview releases?

Same place if it's the current preview version.

@AceHack
Copy link
Author

AceHack commented Jun 11, 2020

It is the current preview version.

@deepchoudhery
Copy link
Member

I have looked at the issue it will be fixed in an upcoming servicing update(version 3.1.4)

@BrunoBlanes
Copy link

Is this by any chance the cause of the Visual Studio error "Import 'Microsoft.WebTools.Scaffolding.Core.ScaffolderFactory.FactoryConfigEvaluator' could not be satisfied." when trying to Scaffold Identity on a Blazor application?

@deepchoudhery
Copy link
Member

@BrunoBlanes I don't think so but I am seeing that error pop up for other users as well. I'm digging into what is causing it. Would you mind opening another issue here and I can get more info off of you.

@BrunoBlanes
Copy link

@deepchoudhery it is done as #1364

@deepchoudhery
Copy link
Member

Fixed in 3.1.4. Closing.

@VGerris
Copy link

VGerris commented Oct 8, 2020

I wonder why this is closed, 3.1.4 is broken : #1387 .

@gvitola
Copy link

gvitola commented Dec 8, 2020

I am facing the same with .NET 5.0 and the package version 5.0.1. Any idea how to fix it?

@TB-Development
Copy link

TB-Development commented 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.

@mhoc4
Copy link

mhoc4 commented Dec 27, 2020

  1. Add a global.json to specify your sdk version.

dotnet new globaljson --sdk-version 3.1.300

step 1 fixed it for me, sdk version 3.0

@ChristianFigueredo
Copy link

ChristianFigueredo commented 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

@gvitola
Copy link

gvitola commented Jan 25, 2021 via email

@backnotprop
Copy link

For mac users, and targeting net5.0 try this stack overflow answer:

https://stackoverflow.com/questions/63584060/aspnet-codegenerator-no-code-generators-available-even-after-adding-microsoft


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests