Get Started with .NET

Building and Running Your First Application

Welcome to .NET Development!

This guide will walk you through the essential steps to build and run your first .NET application. .NET is a versatile, open-source platform for building all kinds of applications, from web and cloud services to desktop and IoT applications.

Prerequisites

Before you begin, ensure you have the following installed:

Step 1: Create a New Project

You can create a new .NET project using the command line interface (CLI) provided by the .NET SDK. Open your terminal or command prompt, navigate to the directory where you want to create your project, and run the following command:

dotnet new console -o MyFirstApp

This command does the following:

Step 2: Navigate to Your Project Directory

Change your current directory to the newly created project folder:

cd MyFirstApp

Step 3: Explore the Project Files

Inside the MyFirstApp directory, you'll find a few key files:

Step 4: Write Your Code

Open the Program.cs file in your code editor. By default, it contains a simple "Hello, World!" program:

using System; namespace MyFirstApp { class Program { static void Main(string[] args) { Console.WriteLine("Hello, World!"); } } }

Feel free to modify the message or add more lines of code to experiment!

Step 5: Build and Run Your Application

You can build and run your application directly from the command line within your project directory:

dotnet run

The dotnet run command first builds your project (if necessary) and then executes the compiled output. You should see the output from your application displayed in the terminal.

Troubleshooting Common Issues

What's Next?

Congratulations on building and running your first .NET application! Here are some ideas for continuing your journey:

  • Explore different project templates: Try dotnet new webapi or dotnet new maui.
  • Learn about C# fundamentals: Dive deeper into variables, control flow, and object-oriented programming.
  • Discover ASP.NET Core for web development.
  • Explore .NET MAUI for cross-platform native UI development.
  • Visit the official .NET documentation for comprehensive guides and API references.