This is my first time using Visual Studio Code and I am trying to run a simple code on it but it is giving me an error that says:
'scriptcs' is not recognized as an internal or external command, operable program or batch file.
I have this as code:
using System;
struct Employee{
public int Id { get; set; }
public string FullName { get; set; }
}
public class MyClass{
public static void Main(){
Employee obj= new Employee();
obj.FullName = "Hello World";
Console.WriteLine(obj.FullName);
}
}
I have tried installing the Scriptcs Runner, but still the same issue. Can anybody suggest something else?
Edit:
After many of your suggestions I tried the following:
Problem is still the same. Getting the above error.
Open the Extensions and install the C# extension: Name: C#, ,Id: ms-vscode.csharp ,Description: C# for Visual Studio Code (powered by OmniSharp). ,Publisher: Microsoft ,VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp
Go to console into a folder of your choice and create a new console project by typing dotnet new console -o TestConsoleApp
This will create a project file TestConsoleApp.csproj
Start VS Code by typing Code .
In VS Code goto Terminal and execute dotnet run --project TestConsoleApp
to run your application. Alternatively you can start Debugging (F5)
This should provide you a good start where you then can use your code.
If you just want to use code snippets, you should try what Athanasios Kataras answered but with that I have no experience.
There is a also video introduction for this available at https://channel9.msdn.com/Blogs/dotnet/Get-started-VSCode-Csharp-NET-Core-Windows
You need both the script runner extension and to install scripts
Installation and information guide is here: http://scriptcs.net/
cinst scriptcs
to install the latest version. Then make sure you install the script runner extension as per this guide: https://www.strathweb.com/2015/11/running-c-scripts-and-snippets-in-visual-studio-code-with-scriptcs/
The extension can be installed directly from VS Code:
You're attempting to run a csharp program without creating it as a project. For simple one-offs that you would like to run quickly without creating a full project, you need the c# script runner. You can install it with the following instructions. Below is a link to the extension's github page for reference.
Go to Extensions, search for scriptcs and install scriptcsRunner. You mention that you have this installed, but it should be all you need for a simple one file program like you have above. Double check that it is the version here: https://github.com/filipw/vscode-scriptcs-runner.git
Alternatively, if you want to create an actual project, you will need to run a few commands within the integrated terminal.
dotnet new console
dotnet run
in the terminalhttps://code.visualstudio.com/docs/languages/dotnet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With