C#Visual Studio代码:构建Hello World可执行文件
我试图用Visual Studio代码构建一个简单的hello world可执行文件,但不知道我在做什么?为了解释,我将重复我的步骤 首先,我在这里遵循简单的教程 一旦我了解了真相,我想我会接受我的C#项目并编译(或构建)该项目。我想他们不会在一开始就讨论这个问题,因为这不是真正的直截了当 首先,我必须指出VisualStudio和VisualStudio代码并不共享相同的知识库(至少在编译时是这样) 下一件事是VisualStudio代码使用任务来构建可执行文件,至少这是我从中得到的 所以我所做的是 步骤1)在windows资源管理器中创建我希望项目驻留的新文件夹C#Visual Studio代码:构建Hello World可执行文件,c#,visual-studio-code,C#,Visual Studio Code,我试图用Visual Studio代码构建一个简单的hello world可执行文件,但不知道我在做什么?为了解释,我将重复我的步骤 首先,我在这里遵循简单的教程 一旦我了解了真相,我想我会接受我的C#项目并编译(或构建)该项目。我想他们不会在一开始就讨论这个问题,因为这不是真正的直截了当 首先,我必须指出VisualStudio和VisualStudio代码并不共享相同的知识库(至少在编译时是这样) 下一件事是VisualStudio代码使用任务来构建可执行文件,至少这是我从中得到的 所以我所
步骤2)打开visual studio并使用终端导航到文件夹
步骤3)键入命令>>dotnet新建控制台
步骤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选择build,什么也没发生
我走到终端,键入dotnetbuild,得到以下终端响应
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
我去寻找我全新的可执行文件,但什么都没有?我试图在这里查看有关microsoft的帮助
但我想我会找到如何在我的任务中使用csc.exe,但我不知道如何使用,我甚至不确定我是否也应该这样做
如果有人知道我做错了什么,请告诉我。我遵循了你的所有步骤,这对我很有效
1> Go command prompt
2> Go to folder .. bin\Debug\netcoreapp2.1
3> Run command dotnet HelloWorldApplication.dll
转到[program\u name]>bin>debug>[there中的\u only\u foler\u]可执行文件应该在那里Ay Caramba。。。我想我是在“编译”或“构建”这两个关键词上磨练了一下,来描述我想要的东西,但一直都是“发布”。谢谢,请遵循此主题:DLL不是可执行的!这就是问题所在。要运行
HelloWorldApplication.dll
,必须使用dotnet.exe
应用程序。这就是为什么您必须执行此答案中所述的dotnet HelloWorldApplication.dll
。