Get Started with Your First .NET App
Welcome to the exciting world of .NET development! In this guide, you'll learn how to create and run your very first .NET application. We'll walk you through the essential steps, from setting up your environment to writing and executing your code.
Prerequisites
Before you begin, ensure you have the following installed:
- The latest .NET SDK. You can download it from the official .NET download page.
- A code editor. We recommend Visual Studio Code, but any editor will work.
Step 1: Create a New Project
Open your terminal or command prompt and navigate to the directory where you want to create your project. Then, run the following command to create a new console application:
dotnet new console -o MyFirstApp
This command does the following:
dotnet new console
: Creates a new project using the console application template.-o MyFirstApp
: Specifies the output directory for the new project, naming itMyFirstApp
.
Navigate into the newly created project directory:
cd MyFirstApp
Step 2: Explore the Project Files
Inside the MyFirstApp
directory, you'll find a few essential files:
MyFirstApp.csproj
: The project file that contains project configuration and dependencies.Program.cs
: The main file where your application's code resides.obj/
andbin/
: Directories for build artifacts (usually ignored by version control).
Step 3: Write Your Code
Open the Program.cs
file in your code editor. You'll see something like this:
Console.WriteLine("Hello, World!");
Let's modify it to print a more personalized message. Replace the existing line with the following:
Console.WriteLine("Welcome to your first .NET app!");
Console.WriteLine("Let's build something amazing together!");
Step 4: Run Your Application
Now, it's time to run your application. Make sure you are still in the MyFirstApp
directory in your terminal. Execute the following command:
dotnet run
You should see the following output in your terminal:
Welcome to your first .NET app!
Let's build something amazing together!
dotnet run
command compiles your project if necessary and then executes the output.
Next Steps
Congratulations! You've successfully created, coded, and run your first .NET application. This is just the beginning of your .NET journey. Here are some ideas for what to explore next:
- Create your first .NET web application.
- Dive deeper into various .NET tutorials.
- Explore the powerful .NET API.
- Learn about common .NET CLI commands.