Scaffolding: Cannot generate controller from cli
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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (5 by maintainers)
I fixed it updating the codegenator package:
dotnet tool uninstall --global dotnet-aspnet-codegeneratordotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4dotnet restoredotnet new globaljson --sdk-version 3.1.300dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Designdotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design -v 3.1.0dotnet restoredotnet buildYou can see your SDKs and runtimes installed with.
dotnet infoyou can see your packages with
dotnet list packageAs for why this happened. No idea, Just downgrading my SDK, .NET core env and the package version worked for me.
@deepchoudhery it is done as #1364