gpt4 book ai didi

C# Visual Studio 代码 : Building a Hello World executable

转载 作者:太空宇宙 更新时间:2023-11-03 16:58:50 24 4
gpt4 key购买 nike

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

首先,我按照这里的简单教程 https://learn.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 输入“Run Build Task”

要求我创建构建任务的提示,我选择了 .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,但我不知道如何使用,我什至不确定我是否也应该这样做?

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

最佳答案

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

关于C# Visual Studio 代码 : Building a Hello World executable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53874894/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com