Visual Studio Code for Developing .NET Core C# Apps on macOS

Visual Studio Code for Developing .NET Core C# Apps on macOS

Yesterday I briefly mentioned my experience of developing a .NET Core C# Console Application on macOS using Visual Studio Code. Since then I have made several .NET Core console applications ( and ASP.NET Core Web Apps ) for kicks and wanted to mention the steps in more detail if you are struggling with the process.

First, in macOS I created a directory for my project and changed to the directory from the macOS Terminal. In this case:

mkdir console2 && cd $_

To get up and running quickly I issued 2 .NET Core commands from within the directory, which create the skeleton of a .NET Core C# Console Application and restore all the necessary packages used by it.

dotnet new
dotnet restore

I then run Visual Studio Code from the macOS Terminal by issuing the command:

code .

Visual Studio Code pops up on the macOS desktop and within about 10 seconds I receive a notification within Visual Studio Code asking me if I want to add the required assets to build and debug the .NET Core Console App. I do want to build and debug the app so I choose "Yes."

Build and Debug C# .NET Core in Visual Studio Code

As I mentioned yesterday, you need to have the C# Extension installed in Visual Studio Code to debug C#. You can install it within Visual Studio Code using the command pallete (CMD-SHIFT-P).

Install C# Extension in Visual Studio Code

Now you can just start programming in C# within Visual Studio Code. I created a quick console application that solves factorials. Just pass the positive integer as a command line argument and it will solve the factorial.

Develop C# .NET Core Console Application in Visual Studio Code

I like to open up the terminal in Visual Studio Code using CTRL-`, and issue the dotnet run command right within the terminal. I am adding 10 as a command line argument to calculate 10!.

Hopefully this helps get you started if you're struggling.