15 minlesson

Setting Up Your Development Environment

Setting Up Your Development Environment

Before writing C# code, you need to set up your development environment. This lesson guides you through installing the necessary tools.

What You'll Need

To develop C# applications, you need:

  1. .NET SDK: The software development kit that includes the C# compiler
  2. Code Editor: A text editor for writing code (we recommend VS Code)
  3. Terminal/Command Prompt: For running commands

Installing the .NET SDK

The .NET SDK is essential – it includes everything needed to build and run C# applications.

Step 1: Download .NET SDK

  1. Visit https://dotnet.microsoft.com/download
  2. Download the latest .NET SDK (not just the Runtime)
  3. Run the installer and follow the prompts

Step 2: Verify Installation

Open a terminal (Command Prompt on Windows, Terminal on macOS/Linux) and run:

bash
1dotnet --version

You should see a version number like 8.0.100 or higher.

Also try:

bash
1dotnet --info

This displays detailed information about your .NET installation.

Installing Visual Studio Code

VS Code is a free, lightweight code editor with excellent C# support.

Step 1: Download VS Code

  1. Visit https://code.visualstudio.com
  2. Download the version for your operating system
  3. Install and launch VS Code

Step 2: Install C# Extension

  1. Open VS Code
  2. Click the Extensions icon in the sidebar (or press Ctrl+Shift+X)
  3. Search for "C#"
  4. Install the C# Dev Kit extension by Microsoft

This extension provides:

  • Syntax highlighting
  • IntelliSense (code completion)
  • Debugging support
  • Code navigation

Creating Your First Project

Let's create a project to verify everything works.

Step 1: Create a Project Folder

Open your terminal and navigate to where you want to store projects:

bash
1cd Documents
2mkdir CSharpProjects
3cd CSharpProjects

Step 2: Create a Console Application

Run the following command:

bash
1dotnet new console -n HelloWorld

This creates a new console application named "HelloWorld".

Step 3: Explore the Project

Navigate into the project folder:

bash
1cd HelloWorld

You'll see these files:

  • HelloWorld.csproj: Project configuration file
  • Program.cs: Your C# source code file

Step 4: Open in VS Code

bash
1code .

This opens VS Code in the current directory.

Understanding the Project Structure

Open Program.cs in VS Code. You'll see:

csharp
1// See https://aka.ms/new-console-template for more information
2Console.WriteLine("Hello, World!");

This is the modern "top-level statements" format introduced in C# 9. It's the simplest way to write a C# program.

Running Your Application

From the Terminal

In the terminal, make sure you're in the project folder and run:

bash
1dotnet run

You should see:

Hello, World!

From VS Code

  1. Open the Run and Debug panel (Ctrl+Shift+D)
  2. Click "Run and Debug"
  3. Select ".NET Core" if prompted

Alternative: Visual Studio (Full IDE)

For Windows users, Visual Studio Community is a full-featured IDE that includes everything:

  1. Visit https://visualstudio.microsoft.com
  2. Download Visual Studio Community (free)
  3. During installation, select the ".NET desktop development" workload

Visual Studio provides:

  • Integrated debugging
  • GUI designers
  • Database tools
  • More advanced features

However, VS Code is sufficient for this course and is cross-platform.

Troubleshooting

"dotnet is not recognized"

The .NET SDK isn't in your PATH. Try:

  • Restart your terminal
  • Restart your computer
  • Reinstall the .NET SDK

VS Code doesn't recognize C#

Make sure you:

  • Installed the C# Dev Kit extension
  • Opened a folder containing a .csproj file
  • Waited for the extension to initialize

Summary

In this lesson, you:

  • Installed the .NET SDK
  • Set up VS Code with the C# extension
  • Created your first C# console application
  • Ran the application using dotnet run

You're now ready to start writing C# code! In the next lesson, we'll create a more interactive "Hello World" program.