Building Your First .NET Core “Hello World” Application Part 1

If you’re new to .NET Core, it may seem daunting at first, but don’t worry - we’ve got you covered. As part of your web development training, it’s important to get hands-on experience. In this tutorial, we’ll guide you through building your first .NET Core application from scratch.

Table of Contents

  1. Prerequisites
  2. Creating a New Project
  3. Understanding the Project Structure
  4. Adding Functionality
  5. Running the Application

Prerequisites

Before starting, make sure you have the .NET Core SDK installed. You can download it from the .NET Core official download page. The SDK includes everything you need to build and run .NET Core applications.

Creating a New Project

We’ll be creating a console application, which is the simplest type of application you can create with .NET Core. Open a terminal or command prompt and navigate to the folder where you want to create your project. Then, type the following command:

dotnet new console -o MyFirstApp

This will create a new console application in a folder named “MyFirstApp”. Navigate into this folder:

cd MyFirstApp

Understanding the Project Structure

In the “MyFirstApp” folder, you’ll see two files: Program.cs and MyFirstApp.csproj.

  • Program.cs: This is the main entry point for the application. It includes a Main method which is run when the application starts.
  • MyFirstApp.csproj: This is the project file that includes information about the project and its dependencies.

Adding Functionality

Let’s add some simple functionality to our application. Open the Program.cs file in a text editor and replace the existing code with the following:

using System;

namespace MyFirstApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, what's your name?");
            string name = Console.ReadLine();
            Console.WriteLine($"Nice to meet you, {name}!");
        }
    }
}

This program will ask for your name and then greet you personally!

Running the Application

To run the application, go back to your terminal or command prompt, make sure you’re in the “MyFirstApp” folder, and then type the following command:

dotnet run

Your application will run, and you’ll be able to interact with it from the terminal.

This marks your first step into the world of .NET Core. As you continue learning .NET Core and ASP.NET Core, you’ll soon be able to build more complex applications, from web apps using ASP.NET Core to data-driven applications using Entity Framework Core, and even build microservices. So, keep learning and happy coding!