I am having some problems at scaffolding when i try to create an Controller.
dotnet aspnet-codegenerator controller -name EmployeeController -m Employee -dc EmployeeContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries
I am with all most recent packages at my .csproj, as you can see:
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="17.3.1" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.3.1" />
<PackageReference Include="Microsoft.Build.Runtime" Version="17.3.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.8">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration" Version="6.0.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGenerators.Mvc" Version="6.0.8" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
</ItemGroup>
For this error, i run the trace at the terminal, review and update all versions of packages and tried to run it again, after dotnet build and dotnet restore.
That's the result:
$ dotnet aspnet-codegenerator controller -name EmployeeController -m Employee -dc EmployeeContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries
[Trace]: Command Line: controller -name EmployeeController -m Employee -dc EmployeeContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries
[Trace]: Executing external command:
dotnet msbuild C:\workspace\c-sharp-workspace\CSharp-EmployeeCrud\CSharp-EmployeeCrud.csproj /t:EvaluateProjectInfoForCodeGeneration /p:OutputFile=C:\Users\bruno\AppData\Local\Temp\l3tsrd1j.2ld;CodeGenerationTargetLocation=C:\Users\bruno\.dotnet\tools\.store\dotnet-aspnet-codegenerator\6.0.8\dotnet-aspnet-codegenerator\6.0.8\tools\net6.0\any;Configuration=Debug -restore
Building project ...
[Trace]: Executing external command:
dotnet build C:\workspace\c-sharp-workspace\CSharp-EmployeeCrud\CSharp-EmployeeCrud.csproj --configuration Debug --framework net6.0
Scaffolding failed.
Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet package reference.
[Trace]: at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.CreateDipatchCommand(IProjectContext context, String[] args, String buildBasePath, String configuration, String tfmMoniker, String shortFramework, ScaffoldingServer server) in /_/tools/dotnet-aspnet-codegenerator/Program.cs:line 251
at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.BuildAndDispatchDependencyCommand(String[] args, String projectPath, String buildBasePath, String configuration, Boolean noBuild, ILogger logger) in /_/tools/dotnet-aspnet-codegenerator/Program.cs:line 189
at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.<>c__DisplayClass19_0.<Execute>b__0() in /_/tools/dotnet-aspnet-codegenerator/Program.cs:line 130
RunTime 00:00:09.48
The error says I have to Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet package reference, but it's already there.
I've tried to run dotnet tool update -g dotnet-aspnet-codegenerator as I saw in [this post][1] but it doesn't make any change:
Tool 'dotnet-aspnet-codegenerator' was reinstalled with the latest stable version (version '6.0.8').
Hope you can help me!
UPDATE:
I've removed the package Microsoft.VisualStudio.Web.CodeGeneration.Tools as BorisR suggest and now I was able to run, but the error now is the following one:
Building project ...
Finding the generator 'controller'...
Running the generator 'controller'...
To scaffold, install the following Entity Framework core packages and try again: Microsoft.EntityFrameworkCore.SqlServer.
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:06.83
It's asking me to install EF Package for SqlServer, but i am using an MySQL DB. Is that correct? Or there is another EF command for create a controller when my database is MySQL?
Thanks. [1]: .NET Scaffolding Failed