Freigeben über


How to create a “Hello World” console application using .NET Core without Visual Studio?

This article gives you a quick guidance on how to create a console application using .NET Core without any IDE like Visual Studio.

Refer: Previous article to get to know bit fundamentals of .NET Core 5

Step 1: Install DNVM using powershell command

Open command prompt in admin mode and run the following:

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}" 

 

Step 2: Install the requested DNX version from the feed

In my below example runtime coreclr of version 1.0.0-rc1-final

dnvm install -a x64 -r coreclr 1.0.0-rc1-final

dnvm install -a x64 -r coreclr 1.0.0-rc1-final 

Step 3: List the DNX version installed

dnvm list

This should show the DNX version installed and active one selected.

 

Step 4: Write to Console App to display “Hello World”

Here is simple code to display “Hello World”, you can copy paste below code into Program.cs file under your application directory.

using System;

public class Program

{

    public static void Main (string[] args)

    {

        Console.WriteLine("Hello World");

    }

}

Step 5: Create a project.json file

We need to have a project.json file to retrieve the dependencies and configuring the references/dependencies for the project. It also determines the runtime which can execute the project.

Copy the below code into project.json file under your application directory.

{

    "version": "1.0.0-*",

    "dependencies": {

    },

    "frameworks" : {

        "dnx451" : { },

        "dnxcore50" : {

            "dependencies": {

                "System.Console": "4.0.0-beta-*"

            }

        }

    }

 

Step 6: Run the .NET Utilities command

.NET utilities(DNU) manages the required packages to run an application and dependencies by installing and restoring the packages for the respective project files.

From the same command prompt windows where we ran the list command, navigate to the application directory folder and run below commands: 

 dnu restore

Now run your application by running below command: 

 dnx run

 This would display “Hello World” in your window.