简体   繁体   English

Visual Studio Code 无法运行 C# 文件

[英]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.我正在开始一个关于 C# 的教程,不幸的是,我的电脑无法处理 Visual Studio,所以我的一个朋友向我推荐了 Visual Studio Code,因为它更轻便。 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.我安装了它,我安装了 .NET Core SDK 和由 OmniSharp 提供支持的 C# 扩展,之后,我在我的桌面中创建了一个文件夹,然后在该文件夹中创建了一个文件夹(然后我在该文件夹中创建了“文件”)。在里面写了一个非常简单的“Hello World”程序。 And when I tried to run it without debugging, it asked me to select an enviroment, and I selected ".NET Core".当我尝试在不调试的情况下运行它时,它要求我使用 select 一个环境,我选择了“.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:它在我的项目文件夹中创建了另一个名为“.vscode”的文件夹,并在该文件夹中创建了一个名为“laucnh.json”的文件,其中包含以下代码:

{
    // 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.之后,屏幕右下角出现一条错误消息,并显示“无法创建 .NET 调试配置。OmniSharp 服务器仍在初始化或已意外退出。”,但我认为我已正确安装所有内容。 Am I missing something?我错过了什么吗?

You can not run a file in C#.您不能在 C# 中运行文件。 Try create a new console application with尝试创建一个新的控制台应用程序

dotnet new console

A {projectName}.csproj and and Program.cs will appear.将出现 {projectName}.csproj 和 Program.cs。 Put your code into the Main method of the Program class and it will probably work将您的代码放入程序 class 的 Main 方法中,它可能会起作用

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

Use dotnet new console to create a new project in C#使用dotnet new console在 C# 中新建项目

  1. This will create a.vscode folder in the directory这将在目录中创建一个.vscode 文件夹
  2. Create a tasks.json file创建tasks.json文件
  3. Create a Launch.json file and add configurations创建 Launch.json 文件并添加配置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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