Getting Started with C# on macOS Using Visual Studio Code

KSHITIJ SHARMA
3 min readMay 13, 2024

--

C# is a powerful programming language developed by Microsoft that enables developers to build a variety of applications ranging from simple console apps to complex enterprise-level solutions. In this article, we’ll guide you through setting up your macOS environment for C# development using Visual Studio Code (VS Code) and then walk you through writing and executing a simple “Hello World” program.

Step 1: Install Visual Studio Code

First, you need to install Visual Studio Code, a lightweight and powerful code editor that supports a multitude of programming languages including C#. It’s widely used for its versatility, performance, and extensive plugin system.

  1. Go to the Visual Studio Code website.
  2. Download the stable build for macOS.
  3. Open the downloaded .zip file and move Visual Studio Code to your Applications folder.

Step 2: Install the .NET SDK

C# programs require the .NET SDK (Software Development Kit). For macOS, you can download it directly from Microsoft.

  1. Visit the .NET download page.
  2. Choose the SDK (Software Development Kit) for macOS.
  3. Follow the instructions to download and install the SDK.

After installation, you can verify that it was installed correctly by opening a Terminal and typing:

dotnet --version

This command will display the version of the .NET SDK installed on your machine.

Step 3: Install the C# Extension in VS Code

To effectively develop in C#, you should install the official C# extension from Microsoft.

  1. Open Visual Studio Code.
  2. Navigate to the Extensions view by clicking on the square icon on the sidebar or pressing Cmd+Shift+X.
  3. Search for “C#”.
  4. Find the C# extension by Microsoft (usually the first result) and click Install.

Step 4: Create Your First C# Program

Now that you have your environment set up, you can start writing your first simple C# program.

  1. Open VS Code.
  2. Create a new folder for your project, and open it in VS Code.
  3. Open the Terminal in VS Code by selecting Terminal > New Terminal from the top menu.
  4. In the Terminal, create a new console application by typing:
dotnet new console -n HelloWorld
  1. This command creates a new folder named HelloWorld containing a simple "Hello World" program.
  2. Navigate to the project folder by typing:
cd HelloWorld

Step 5: Explore the Generated Code

VS Code and the .NET CLI have automatically generated a simple C# program for you. Open the Program.cs file in your VS Code editor. It should look like this:

using System;

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

Step 6: Run Your Program

You’re now ready to run your first C# program.

  1. Ensure you are in the project’s root directory in your Terminal (inside the HelloWorld folder).
  2. Type the following command to run your application:
dotnet run

This command compiles and executes your program, and you should see “Hello World!” printed in the terminal.

Conclusion

Congratulations! You have successfully set up your macOS environment for C# development and executed your first C# program using Visual Studio Code. This setup provides a robust platform for developing further more complex C# applications and exploring the rich ecosystem of .NET.

--

--