No executable found matching command "dotnet-script"

1.2k Views Asked by At

Why doesn't dotnet script run in PowerShell after installation? I closed and reopened all PowerShell instances after installing.

PowerShell throws this error when I run dotnet script init:

No executable found matching command "dotnet-script"

Edit:

  • dotnet script does run in cmd.exe
  • The dotnet and .dotnet\tools folders are present in PATH
3

There are 3 best solutions below

0
On BEST ANSWER

I solved by:

  1. Removing old PATH entries in case PATH was too large (source)
  2. Restarting the computer because PowerShell's $env:PATH wasn't updating even after closing/reopening all PowerShell instances (source)
0
On

While I'm sure that your own solution helped, it's worth digging deeper:

The dotnet and .dotnet\tools folders are present in PATH

To produce your symptom, the former must be true, but not the latter:

It is dotnet.exe that issues the error message (implying that dotnet.exe itself indeed is in the PATH).

The error message indicates that a tool named script could not be located, implying that an executable named dotnet-script.exe could not be found in the PATH, because that's the executable name that dotnet constructs behind the scenes when you call dotnet script.

With a properly set up PATH (and, of course, dotnet-script installed), dotnet-script.exe should be found via the $HOME\.dotnet\tools directory in the PATH.

$HOME\.dotnet\tools is an entry stored as part of the user-specific PATH additions in the registry, and your PowerShell session seemingly hadn't picked up that entry yet - which can happen for the reasons mentioned in your answer.

3
On

Most likely the folder containing dotnet is not in your PATH environment variable. Add it to that variable.

Also note that dotnet will install in two locations if you install both x86 and x64 versions, and will only ever pick one if both end up in PATH. This can lead to very strange results when updating!