简体   繁体   中英

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?

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://docs.microsoft.com/en-us/dotnet/core/tutorials/cli-create-console-app

Use dotnet new console to create a new project in C#

  1. This will create a.vscode folder in the directory
  2. Create a tasks.json file
  3. Create a Launch.json file and add configurations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM