如何使用 Visual Studio 代码创建新的可执行 C# 项目

How to create a new executable C# project with Visual Studio Code

我想用 Visual Studio Code + omnisharp 创建一个新的可执行项目。 它适用于 dll 但不适用于 exe 文件。

  1. 为我的新项目(例如 myApp)创建了一个文件夹
  2. 打开Visual studio代码->文件->打开文件夹
  3. 打开内部 VSC 终端并输入以下命令

代码:

dotnet new console (pressed yes in popup)
dotnet restore
dotnet run
//hello world was visible in terminal (what means it works)
dotnet build

构建成功,但创建了一个 dll 文件。

顺便说一句:我用它来寻求帮助 -> https://github.com/dotnet/docs/blob/master/docs/core/tutorials/with-visual-studio-code.md

您使用的是 dotnet 核心,因此可执行文件仍在 .dll 中。要运行文件,运行dotnet nameofdll.dll

dotnet core 是跨平台的,为了减少与 windows 的紧密耦合,.exe 不再用于可执行文件。

如果您希望您的应用程序 Windows 依赖,您需要将您的应用程序改为以 .Net Framework 为目标 - 这样您将获得一个 .exe。