Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code can't run C# file

I am starting a tutorial about C# and, unfortunely, my PC can't handle Visual Studio, so a friend of mine recommended me Visual Studio Code, because it's a lot more light. I installed it, I installed the .NET Core SDK and the C# extension powered by OmniSharp, and after that, I created a folder in my Desktop, then I created my "file.cs" in that folder (inside VS Code), and I had written a really simple "Hello World" program inside it. And when I tried to run it without debugging, it asked me to select an enviroment, and I selected ".NET Core". It created another folder inside my project folder called ".vscode" and inside that folder it created a file called "laucnh.json" that contains the following code:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": []
}

After that, an error message appears on the bottom right corner of the screen and says "Cannot create .NET debug configurations. The OmniSharp server is still initializing or has exited unexpectedly.", but I think that I installed everything correctly. Am I missing something?

like image 406
AmanoSkullGZ Avatar asked Aug 09 '26 17:08

AmanoSkullGZ


1 Answers

You can not run a file in C#. Try create a new console application with

dotnet new console

A {projectName}.csproj and and Program.cs will appear. Put your code into the Main method of the Program class and it will probably work

https://learn.microsoft.com/en-us/dotnet/core/tutorials/cli-create-console-app

like image 192
Stelios Giakoumidis Avatar answered Aug 11 '26 06:08

Stelios Giakoumidis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!