首页 > 解决方案 > C# Visual Studio Code:构建 Hello World 可执行文件

问题描述

我正在尝试在 Visual Studio Code 中构建一个简单的 hello world 可执行文件,但不知道我做错了什么?为了解释,我将回顾我的步骤。

首先,我按照这里的简单教程https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code

一旦我跌到谷底,我想我会接受我的 C# 项目并编译(或构建)该项目。好吧,我想他们不会在刚开始的时候讨论这个,因为它不是真正的直截了当。

首先,我必须弄清楚 Visual Studio 和 Visual Studio Code 不共享相同的知识库(至少在编译时)。

接下来是visual studio code使用Tasks来构建可执行文件,至少这是我从这个How do you compile a console application with VS Code (Windows platform) 中得到的?

所以我所做的是

步骤 1)在我希望我的项目驻留的 Windows 资源管理器中创建新文件夹
步骤 2)打开 Visual Studio 并使用终端导航到该文件夹
​​ 步骤 3)键入命令 >>dotnet new console
步骤 4)键入命令 >> dotnet restore
步骤 5)确保我的代码看起来像

using System; //The using keyword is used to include the system namespace in the program

namespace HelloWorldApplication //A namespace is a collection of classes
{
    class HelloWorld
{
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.ReadKey();
       }
    }
}

之后我按F1输入“运行构建任务”

提示我创建一个构建任务,我选择了 .NET core 创建一个 tasks.json 文件

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "label": "build",
        "command": "dotnet build",
        "type": "shell",
        "group": "build",
        "presentation": {
            "reveal": "silent"
        },
        "problemMatcher": "$msCompile"
    }
]
}

现在我按 ctrl+shift+b 选择构建并且没有任何反应。

我走到终端并输入 dotnet build 并得到以下终端响应

d:\VS_Sandbox\HelloWorldApplication>dotnet build
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for d:\VS_Sandbox\HelloWorldApplication\HelloWorldApplication.csproj...
  Generating MSBuild file d:\VS_Sandbox\HelloWorldApplication\obj\HelloWorldApplication.csproj.nuget.g.props.
  Restore completed in 134.6 ms for d:\VS_Sandbox\HelloWorldApplication\HelloWorldApplication.csproj.
  HelloWorldApplication -> d:\VS_Sandbox\HelloWorldApplication\bin\Debug\netcoreapp2.2\HelloWorldApplication.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.03

我去哪里寻找我全新的可执行文件,什么也没有?我试图去看看这里的微软帮助https://code.visualstudio.com/docs/editor/tasks

但我以为我会找到如何在我的任务中使用 csc.exe 但我不知道如何使用,我什至不确定我是否也应该这样做?

如果有人知道我做错了什么,请告诉我。

标签: c#visual-studio-code

解决方案


转到 [program_name]>bin>debug>[the_only_foler_in_there] 可执行文件应该在那里


推荐阅读