Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Visual Studio Code: Building a Hello World executable

I am attempting to build a simple hello world executable in Visual Studio Code and don't know what I am doing incorrect? and to explain I will go over my steps.

To start I was following the simple tutorial here https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code

Once I got down to the bottom I thought I would take my C# project and compile(or build) the project. Well I guess they don't go over this near the beginning because it's not real straight forward.

First of all I had to figure out that Visual Studio and Visual Studio Code do not share the same knowledgebase (at least when it comes to compiling).

The next thing is that visual studio code uses Tasks to build the executable, well at least that is what I got from this How do you compile a console application with VS Code (Windows platform)?

So what I did was

Step 1) Create new folder in windows explorer where I wanted my project to reside
Step 2) Open up visual studio and using the terminal navigate to the folder
Step 3) Type the command >>dotnet new console
Step 4) Type the command >>dotnet restore
Step 5) Make sure my code looks like

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();
       }
    }
}

After that I pressed F1 typed in "Run Build Task"

A prompt asking me to create a build task where I selected .NET core creating a tasks.json file

{
// 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"
    }
]
}

Now I press ctrl+shift+b select build and well nothing happens.

I went down to the terminal and typed dotnet build and got the following terminal response

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

To which I go and look for my brand new executable and well nothing? I attempted to go take a look at the help on microsoft here https://code.visualstudio.com/docs/editor/tasks

but thought I was going to find how to use csc.exe in my tasks but I don't know how and I am not even sure I am supposed too?

If anyone knows what I am doing wrong please let me know.

like image 962
DisplayName001 Avatar asked Dec 20 '18 19:12

DisplayName001


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.


1 Answers

Go to [program_name]>bin>debug>[the_only_foler_in_there] the executable should be there

like image 184
Kai Avatar answered Oct 13 '22 17:10

Kai