Dis*_*001 6 c# visual-studio-code
我正在尝试在 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 代码使用 Tasks 来构建可执行文件,至少这是我从这篇文章中得到的你如何使用 VS Code(Windows 平台)编译控制台应用程序?
所以我所做的是
第 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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
之后我按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"
}
]
}
Run Code Online (Sandbox Code Playgroud)
现在我按 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
Run Code Online (Sandbox Code Playgroud)
我去那里寻找我全新的可执行文件,什么都没有?我试图去看看微软这里的帮助https://code.visualstudio.com/docs/editor/tasks
但我想我会找到如何在我的任务中使用 csc.exe 但我不知道如何使用,我什至不确定我也应该这样做?
如果有人知道我做错了什么,请告诉我。
小智 -1
我遵循了你的所有步骤,它对我有用。
1> Go command prompt
2> Go to folder .. bin\Debug\netcoreapp2.1
3> Run command dotnet HelloWorldApplication.dll
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9583 次 |
| 最近记录: |