Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No executable found matching command "dotnet-aspnet-codegenerator" asp.net core 2.1 project in mac

I am following a tutorial from https://learn.microsoft.com/en-us/aspnet/core/tutorials/razor-pages-mac/model?view=aspnetcore-2.1 on creating an asp.net core 2.1 project in mac. When trying to scaffold a model I get an error:

No executable found matching command "dotnet-aspnet-codegenerator"

Most of the solutions in different websites suggest using DotNetCliToolReference for Microsoft.VisualStudio.Web.CodeGeneration.Tools which did not help. However, it is mentioned that all the DotNetCliToolReference can be removed in asp.net core 2.1 https://learn.microsoft.com/en-us/aspnet/core/migration/20_21?view=aspnetcore-2.1. I even tried adding DotNetCliToolReference for Microsoft.VisualStudio.Web.CodeGeneration.Tools with version 2.1.0-preview1-final (the latest version) and 2.0.4 but it resulted in another error:

Version for package Microsoft.VisualStudio.Web.CodeGeneration.Tools could not be resolved.

What am I missing? How can this issue be solved?

Package references I am using:

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.1.0-preview1-final" />
</ItemGroup>
like image 501
ranjeep Avatar asked Jul 02 '18 00:07

ranjeep


2 Answers

After binging through various sites and using the help of senior developers, I was finally able to fix the issue. I found that code generation tool, used for scaffolding of model, became a global .NET Core CLI tool in the 2.1 release. So, instead of just adding package reference it should be installed globally. For more details refer to https://github.com/aspnet/Docs/issues/6894. The command to install code generation tool globally is:

dotnet tool install --global dotnet-aspnet-codegenerator

It will install latest version of code generation tool.

like image 154
ranjeep Avatar answered Oct 18 '22 12:10

ranjeep


As ranjeep said:

dotnet tool install --global dotnet-aspnet-codegenerator

And in the next step you might be faced with the fact that the code generator cmd will not list its generators when you try any of these:

dotnet aspnet-codegenerator -h
dotnet-aspnet-codegenerator -h

The Solution is to also name the project that you want to work on. You HAVE to do this EVEN if you are working in the Package Manager Console with the right project selected in the dropdown.

This will work:

dotnet-aspnet-codegenerator -h -p "C:\Projects\MyProject.csproj"
like image 2
Jpsy Avatar answered Oct 18 '22 12:10

Jpsy