This post contains a step by step guide to fix the error “The term ‘scriptcs’ is not recognized as an internal or external command, operable program or batch file” that you receive while running a C# program (.net core) in Visual Studio code using code runner extension.
Steps to replicate the ‘scriptcs’ not recognized error:
- Open Visual Studio code.
- In your workspace directory, create a new .Net project.
- To create a .Net project, type
dot net new consolein VS code terminal to create a console application.
- A Hello World C# program is created that outputs “Hello World” to console.
- If you run the newly created program using
dotnet runcommand, it works and the console prints “Hello World”.
- Now, install the code runner extension for Visual Studio code.
If you use code runner extension, you do not need to type the run command every time you want to run your program. With just a single click, all types of programs run.
- Open the extension panel in VS code and search for code runner.
- Click on Install button to install code runner extension.
- Open VS code explorer and open the .CS file
- Now, a “run code” option appears on the top-right corner of VS code.
This button is provided by the code runner extension, and can run programs for almost all languages.
- Click on the “run code” button to run the program. This gives the error “The term ‘scriptcs’ is not recognized as an internal or external command, operable program or batch file“.
‘scriptcs‘ is a utility that helps in writing and executing C sharp code. The code runner extension calls the ‘scriptcs‘ command to run C# code by default.
To fix the ‘scriptcs’ command not found error, either install scriptcs on your computer or follow the below steps in this post.
Steps to fix “‘scriptcs’ is not recognized as an internal or external command” error:
- Open Settings in VS code.
- Under Extensions section, select the “Run code configuration“.
- Look for the “Run in Terminal” option and check it.
This option appears once the code runner extension is installed and with this, the output is shown in the integrated terminal of VS code.
- In the same settings screen, on the top right corner, you have the “open json settings” button; open it.
Or, you can open “user json setting” as well. Both are same.
- The settings.json file opens, let’s add a new entry here.
- At the bottom of the json file, type
code-runner.executormapand select the suggested option.
Whenever you run the code directly through the code runner, the commands that are run based on the language is listed in this executormap.
- Search for csharp in the list and scriptcs command is executed (whenever you run a C# prgram).
- Change this scriptcs to “dotnet run“.
The new entry becomes –
"csharp": "dotnet run"
- Save the settings.json file.
- Open your code file and run the code using code runner icon.
This time the program runs successfully as behind the scene, code runner is triggering “dotnet run” command instead of “scriptcs“.
That is how you can fix “‘scriptcs’ is not recognized as an internal or external command, operable program or batch file” error in Visual Studio code while running .Net core (C#) program. If you are still facing the error, let us know in the comments and we will try to help you out.