6
votes

I'm learning ASP.net, so I'm reading https://docs.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?

4
are you sure you run exactly dotnet aspnet-codegenerator? your error says: dotnet-dotnet-aspnet-codegenerator does not exist so it looks like you tried to run: dotnet dotnet-aspnet-codegenerator - Konrad
Yes I have run: dotnet aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages\Movies --referenceScriptLibraries AND dotnet-aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages\Movies --referenceScriptLibraries AND dotnet dotnet-aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages\Movies --referenceScriptLibraries - None of these three commands does work. :( - JarsOfJam-Scheduler
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. - JarsOfJam-Scheduler
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 :(... - JarsOfJam-Scheduler

4 Answers

10
votes

export PATH=$HOME/.dotnet/tools:$PATH was needed, as indicated for Core MVC (https://docs.microsoft.com/fr-fr/aspnet/core/tutorials/first-mvc-app/adding-model?view=aspnetcore-3.0&tabs=visual-studio-code). This indication was forgotten for Core Razor . . .

4
votes

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/

2
votes

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.
1
votes

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 :(...