Getting Started with .NET Core

Welcome to the world of .NET Core! This guide will walk you through the essential steps to set up your development environment and create your first .NET Core application.

Prerequisites

Before you begin, ensure you have the following installed on your system:

  • Operating System: Windows, macOS, or Linux. .NET Core is cross-platform.
  • Text Editor or IDE: You can use any text editor like VS Code, Sublime Text, or a full-fledged IDE like Visual Studio or JetBrains Rider.

Installation

The easiest way to get started is by installing the .NET SDK (Software Development Kit). The SDK includes the .NET runtime, libraries, and the command-line interface (CLI) tools you'll need.

  1. 1

    Download the .NET SDK: Visit the official .NET download page: dotnet.microsoft.com/download. Choose the latest LTS (Long-Term Support) or current release appropriate for your operating system.

  2. 2

    Run the installer: Follow the on-screen instructions for your operating system. The installer will add .NET to your system's PATH.

  3. 3

    Verify the installation: Open a new terminal or command prompt and run the following command to check if the SDK is installed correctly:

    dotnet --version

    You should see the installed .NET SDK version number.

Creating Your First App

Let's create a simple "Hello, World!" console application using the .NET CLI.

  1. 1

    Create a project directory: Open your terminal and create a new directory for your project. Navigate into it:

    mkdir MyFirstDotnetApp
    cd MyFirstDotnetApp
  2. 2

    Create a new console application: Use the dotnet new command to create a new console project:

    dotnet new console

    This command creates several files, including Program.cs and a project file (e.g., MyFirstDotnetApp.csproj).

  3. 3

    Examine Program.cs: Open the Program.cs file in your text editor or IDE. It should look something like this:

    // Program.cs
    using System;
    
    var builder = WebApplication.CreateBuilder(args);
    var app = builder.Build();
    
    app.MapGet("/", () => "Hello World!");
    
    app.Run();

    This is a minimal web API example. For a simple console app, the content would be more like:

    // Program.cs (for Console App)
    using System;
    
    Console.WriteLine("Hello, World!");

    The dotnet new console command typically creates the latter by default for a console project.

Running Your App

Now, let's run the application you just created.

  1. 1

    Build and run: In your terminal, from within the project directory (MyFirstDotnetApp), run the following command:

    dotnet run

    The .NET CLI will compile your code and then execute it.

  2. 2

    See the output: You should see the following output in your terminal:

    Hello, World!

Next Steps

Congratulations! You've successfully set up .NET Core and run your first application. Here are some resources to continue your learning journey:

  • Explore tutorials to build various types of applications (web APIs, MVC, Blazor, etc.).
  • Dive deeper into Core Concepts to understand the architecture and features of .NET Core.
  • Refer to the API Reference for detailed information on .NET libraries.
Explore .NET Core Tutorials