.NET Core C# Development Setup On Apple Silicon Mac

Yuqing Lu
5 min readJun 26, 2022

--

This article demonstrates my local development setup on a MacBook Pro M1, which works for both .NET 3.1 and .NET 6.0 Core Apps using a MSSQL database, and can be hosted with Docker over Https.

Install .NET 6.0

Go to: https://dotnet.microsoft.com/en-us/download and download “.NET SDK Arm64”. Install the SDK, then verify it’s successfully installed from the terminal (I use iTerm2).

In fact, because of “Rosetta 2”, the translation layer that translates apps built for Intel so they will run on Apple Silicon, I found .NET 6.0 SDK x64 works quite well on Mac M1. But why go “Non-native” when we can go “Native”, when the editor/IDE like Visual Studio and Visual Studio Code now supports macOS Arm64.

Install .NET 3.1

Go to: https://dotnet.microsoft.com/en-us/download/dotnet/3.1 only x64 installer is available for macOS, download it and install.

This is where things get interesting, open terminal and check .NET SDKs.

.NET 3.1 is missing, where is it? As I mentioned above, .NET x64 SDK works on Mac M1 thanks to Rosetta 2, it’s however installed under a different path than its Arm64 peer. Let’s check from terminal again:

Obviously, Arm64 SDKs are installed under /usr/lcoal/share/dotnet whereas x64 SDKs are installed under /usr/local/share/dotnet/x64 The $PATH variable however only contains the Arm64 path.

To run .NET 3.1, there are 2 options:

  1. Set an alias “dotnetx64” in file “~/.zshrc”, reload the .zshrc file or start a new terminal session, run command “dotnetx64” instead of “dotnet”
Add an alias in ~/.zshrc for dotnet x64 sdks
Check on terminal with “dotnetx64”

2. Add the x64 path as prefix to $PATH variable, run command “dotnet”. This approach only works in current terminal session

Install VSCode and C# Extensions

I use VSCode for development. Go to: https://code.visualstudio.com/download I’d like to install the “Apple Silicon” version if only .NET 6.0 and above is needed. Since I have to work with some .NET 3.1 apps at the moment, I chose “Universal” and install.

Add Omnisharp C# Extensions on VSCode, the latest 1.25.0 requires SDK 6.0 and above, so I manually downgraded the installation to 1.24.4

Install Docker Desktop

Docker is essential for my local development setup as it is required to run MSSql database on macOS. Meanwhile, I like docker :-) It is very useful!

Go to: https://docs.docker.com/desktop/mac/install/ and select “Mac with Apple chip”, install and verify docker is running:

Setup MSSql server

Most applications I work on are based on .NET backend with Microsoft SQL server (or SQL Server Express). MacOS however doesn’t provide native support to the Microsoft technology so Docker is the way to go.

For Apple Silicon Mac, make sure to use a SQL server image that supports Arm64, such as Azure-SQL-Edge https://hub.docker.com/_/microsoft-azure-sql-edge (Note: sqlcmd tool is not available inside the ARM64 version of SQL Edge containers.)

Run from terminal:

Install Azure Data Studio by following https://docs.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver16 instructions on “macOS installation”. Create a new connection on Azure Data Studio by using credentials created to run the mssql container.

The last step to setup mssql database is changing the “Connection String” value on individual application by passing the value as an environment variable, I prefer using a docker-compose file so I’ll illustrate at the next step.

Setup Docker with Https, Dockerfile and docker-compose yaml file

The step to setup hosting .NET core app via https locally is optional, I don’t see running an app on “http://localhost” instead of “https://localhost” for local development is a problem. On the other hand, it is not difficult to do, so I’ll just do it.

Run these 2 command lines from terminal, replace the password field.

Create a Dockerfile, be sure to use a base image with “arm64v8” tag. Below is an example for .NET 3.1 app, the same template also works for .NET 6.0

Create a docker-compose.yaml file, for this application, https port 5001 are exposed. Among the environment variables, “ConnectionStrings__MyDatabase” value overwrites the database connection string hard coded in .NET Core appsettings.Development.json file.

Run “docker compose up” from terminal, until:

Now open browser, I am seeing my application running on https://localhost:5001 😊

--

--

Yuqing Lu

Consultant at Bouvet Rogaland 🇳🇴. I like solving problems and sharing the knowledge I've gained. Python, C#, .NET, Docker, Azure.