Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core CRUD tool: command not found but actually installed

I'm learning ASP.net, so I'm reading https://learn.microsoft.com/fr-fr/aspnet/core/tutorials/razor-pages/model?view=aspnetcore-3.0&tabs=visual-studio-code and in the section Scaffold the movie model, I must install and run the CRUD tool (ASP.net Core dotnet-aspnet-codegenerator). The problem I encounter is I can't use their tool, an error is output ; however I could install it. Below are the details.

So I'm following the three-steps tutorial to use this CRUD code generator (link given above). I quote:

  1. Open a command window in the project directory (The directory that contains the Program.cs, Startup.cs, and .csproj files).

✔ It worked.

  1. Install the scaffolding tool: dotnet tool install --global dotnet-aspnet-codegenerator

✔ It worked and now if I try to re-install it, it outputs that it's already installed.

  1. For macOS and Linux: Run the following command: dotnet aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages/Movies --referenceScriptLibraries

🐛 It doesn't work. Here is the output error:

Could not execute because the specified command or file was not found. Possible reasons for this include: * You misspelled a built-in dotnet command. * You intended to execute a .NET Core program, but dotnet-dotnet-aspnet-codegenerator does not exist. * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

Question : How can I debug it to make this command work?

like image 873
JarsOfJam-Scheduler Avatar asked Oct 03 '19 09:10

JarsOfJam-Scheduler


Video Answer


3 Answers

Oh, oh... "Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed." - i didn't read it, this is ouput by the CLI at the installation of the codegenerator.

UPDATE: it didn't solve my problem (I re-run my computer & Ubuntu session) with both versions 3.0.0 and 2.1.10 of the codegenerator :(...

like image 75
JarsOfJam-Scheduler Avatar answered Oct 21 '22 16:10

JarsOfJam-Scheduler


Sometimes the latest version might be inconsistent. try with older versions and see if there is any difference. Start with highest version before your current one and go down to find one that actually works. How to install older vesions:

dotnet tool install --global dotnet-aspnet-codegenerator --version {version}

You may find version history in the nuget page:
https://www.nuget.org/packages/dotnet-aspnet-codegenerator/

like image 30
Siavash Rostami Avatar answered Oct 21 '22 16:10

Siavash Rostami


On Windows 10

In my case the installer added the wrong path to the Path environment variable.
The path added was pointing to a non existing folder under Programs. It needs to point to dotnet-aspnet-codegenerator.exe.
For me the correct path was in my user folder: ~\.dotnet\tools

You can check if the correct path was added by running: echo $env:Path
If the path is missing or incorrect you just need to add the correct path to the Path system environment variable.

You might be able to test this by using PowerShell to set your local variable: $env:Path += ";C:\Users\<YOUR_NAME_HERE>\.dotnet\tools"
But I haven't tried this.


To fix it globally

  1. Start typing Environment in the windows search and you should see the Control panel option to Edit system environment variables.
  2. Click the Environment Variables... button in the lower right corner.
  3. Under System variables find and select the Path variable, then click Edit.
  4. Check if the path to dotnet-aspnet-codegenerator.exe is there and if not click New and add it.
  5. Restart your computer.
like image 2
Søren Ullidtz Avatar answered Oct 21 '22 17:10

Søren Ullidtz