[Setup] C# Development Environment
To write and run C# programs, you need the .NET SDK (Software Development Kit). This page walks you through installing the SDK and running your first program.
Installing the .NET SDK
- Download the .NET SDK from dotnet.microsoft.com.
- Run the installer and follow the on-screen instructions.
- Run the following in Terminal (or Command Prompt) to verify the installation.
dotnet --version
If a version number is displayed, the installation is complete.
Creating and Running a Project
C# programs are managed as projects. You can create, build, and run a project using the dotnet command.
1. Create a project
dotnet new console -n HelloApp cd HelloApp
dotnet new console creates a console application template. -n HelloApp sets the project name.
The following files are created.
| File | Description |
|---|---|
| Program.cs | The main source file. Write your code here. |
| HelloApp.csproj | The project configuration file. |
2. Review and edit the source code
Open the auto-generated Program.cs and you will see the following code.
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
Try editing it to something like this.
Console.WriteLine("Hello, World!");
Console.WriteLine("The C# environment is set up successfully.");
3. Run
dotnet run
If Hello, World! and The C# environment is set up successfully. are displayed in the console, you're all set.
Choosing an Editor or IDE
| Tool | Description |
|---|---|
| Visual Studio | Microsoft's integrated development environment. The Community edition is free on Windows. Offers rich debugging and code completion features. |
| Visual Studio Code | A lightweight editor. Installing the C# Dev Kit extension adds code completion and debugging support. |
| Rider | JetBrains' IDE. Runs on Windows, macOS, and Linux. |
It is a good idea to get comfortable with the dotnet run workflow on the command line first, then choose your preferred editor.
Commonly Used dotnet Commands
| Command | Description |
|---|---|
| dotnet new console | Creates a console application project. |
| dotnet run | Builds and runs the project. |
| dotnet build | Builds the project (without running it). |
| dotnet test | Runs a test project. |
If the Command Is Not Found
If your terminal displays dotnet: command not found, the PATH may not be configured correctly. Follow the steps below to check and fix the issue.
1. Find the command location
Check where the command is located.
which dotnet
If not found, check common installation locations.
ls /usr/local/share/dotnet/dotnet ls ~/.dotnet/dotnet
2. Check which shell you are using
echo $SHELL
If /bin/zsh is shown, edit ~/.zshrc; if /bin/bash is shown, edit ~/.bashrc.
3. Add to PATH
Once you know the command location, add the PATH to your shell configuration file.
For macOS (zsh):
echo 'export DOTNET_ROOT="/usr/local/share/dotnet"' >> ~/.zshrc echo 'export PATH="$DOTNET_ROOT:$PATH"' >> ~/.zshrc source ~/.zshrc
For Linux (bash):
echo 'export DOTNET_ROOT="/usr/local/share/dotnet"' >> ~/.bashrc echo 'export PATH="$DOTNET_ROOT:$PATH"' >> ~/.bashrc source ~/.bashrc
DOTNET_ROOT is an environment variable pointing to the .NET SDK installation directory. It is a good practice to set it alongside PATH, as some tools reference it.
For Windows, go to "Advanced System Settings" → "Environment Variables" → "Path" to add the entry. The installer usually sets this automatically, but if you installed manually, check that it is configured correctly.
If you find any errors or copyright issues, please contact us.