Developing on a M1 Mac with Visual Studio for Mac
Hi! We recently posted about how Visual Studio for Mac is supporting Apple Silicon / M1 architecture through the Rosetta translation layer starting in version 8.9, and we’re working towards native support. We’ve been using and testing with M1 Macs, but it’s always great to hear how .NET and Visual Studio for Mac are working for our customers in the real world. We’ve invited Aaron LaBeau, an MVP and seasoned Mac developer, to share his experiences. Thanks, Aaron!
Apple’s recent news of switching processors from the Intel x86 family of processors to custom processors has caused a lot of talk among the development community. The M1 processor is a custom ARM 64-bit processor and is based on the popular A series processors that Apple has been designing and shipping in mobile devices for years. Apple is now shipping several models of computers all with M1 processors. I have been using an M1 Mac Mini since the launch of the M1 building software with .NET tools and my experience has been pretty good so far… for the most part. When I tell developers “Hey I’m running everything on a M1 Mac Mini,” I get a lot of questions about support of various development tools used to build .NET applications and services that run in Azure.
How does Visual Studio for Mac run on M1? First, keep in mind that I don’t work for Microsoft or Apple, and I’m just sharing my personal experience here. Visual Studio for Mac runs on M1 thanks to a translation layer called Rosetta 2 which translates x86 instructions to ARM64. It’s designed to run without end users noticing it, and “for the most part” it works like this. The performance feels the same as running on my 2019 MacBook Pro 16” with a i9 Processor fully loaded with max RAM and storage, maybe even faster at times.
You’ve seen me state “for the most part” several times so far. With any massive change in technology there will be some hiccups. Large complex tools with many dependencies will take time to get ARM64 support fully working. I’m not going to lie, there has been some small amount of pain when using a M1 Mac to develop software. Most of it is around things I’ve had not work and then had to research fixes. I would like to share with you my experiences below.
Out of the box Visual Studio for Mac runs great for ASP.NET development of APIs and Razor Webpages. I’ve worked on multiple projects and a few Blazor apps and I’ve been able to open them and debug without issues.
When you go to download Edge, select the “Mac with Apple chip” version if you have M1 processor and you will get an optimized version of the browser.
As you can see from my screenshot below, I have Microsoft Edge selected to use to debug with and I have the Blazing Pizza app debugging in Visual Studio for Mac without issues.
For those web developers using other open-source software and tools, Homebrew now supports the M1 processor. You can find the download for Homebrew here.
While homebrew does support the M1 processor, some tools will not install properly without changes to the way you install them. You can tell the command line which architecture to use when running commands. For example, until the Node.js v16.0.0 release (which included ARM support), I used the following syntax to tell Homebrew to install node with native M1 processor support:
arch -arm64 brew install node
This would tell brew to install the arm version of node. If you wanted to support X86 and use the Rosetta 2 translation layer you could install it with:
arch -x86_64 brew install node
Even running complex projects, like a project based on Jason Taylor’s Clean Architecture .NET Core NuGet package are possible. For this, I simply followed the directions from the GitHub repo and thanks to the awesome integrated Terminal support in Visual Studio for Mac I launched the Angular Web App which is node based right within the Terminal in Visual Studio for Mac. The terminal even supports all my custom fonts and colors I have setup in zsh. I don’t know which developer worked on the terminal plugin, but they deserve a virtual high five for this because it’s one of my favorite features in Visual Studio for Mac.
Also, did you know that you can open more than one Terminal window in Visual Studio for Mac? This is something I think most people look over and I love that I can have more than one tab open at a time. To open another Terminal tab just click the button on the right side of the window.
I can’t express how much this has helped my workflow given I still use the command line for a lot of things like git.
On the Xamarin front, life is pretty good unless you’re using Android emulators. The good news is that .NET expert, Podcast host, and internet streamer James Montemagno has a great article already up on how to work around this which you can read in his blog post on how he setup his M1 Mac for Xamarin Development
I would note I did a different work around to get my Android emulators working which involved the following:
- Installing Android Studio from the Android Developer Portal (I use this for complex profiling and debugging of mobile apps)
- Using the AVD Manager setup a new emulator using the arm64 image
Once I did this – Visual Studio for Mac saw the device and I could use it to push builds and debug without issues. It’s also very fast for an emulator – way faster than the emulators I used to use in the past and with Hot Reload working I feel like I can do very rapid mobile development.
The one minor pain is Docker support. The Docker Desktop client now runs on an M1 Macs, but most of the docker images have not been updated for the ARM64 architecture. Because of this, running the standard SQL Server in Docker on your local machine isn’t possible today via Docker. I do have a work around though – Azure SQL Edge has been ported to ARM64 and thus can run on Docker for M1 on your Mac.
A sample on how to get started using this Docker image is:
docker run -e "ACCEPT_EULA=1" -e 'MSSQL_SA_PASSWORD=P@ssword123' -e "MSSQL_PID=Developer" -e "MSSQL_USER=SA" -p 1433:1433 -d --name=sql mcr.microsoft.com/azure-sql-edge
Once running you can use Azure Data Studio to connect to the docker image running on localhost (127.0.0.1).
I’ve used Azure SQL Edge with Entity Framework Core and EF 5 for testing my ASP.NET Core projects and it works fine on my machine with a standard connection string.
Honorable Mention: Visual Studio Code
For those that also use Visual Studio Code – there is now support for ARM64 and the latest build should have universal support. You can read more about this in the release notes.
While the first couple of weeks trying to develop software on a M1 Mac Mini was painful, the entire Microsoft team of development tools have come together to resolve the major problems developing .NET software on a M1 processor. Visual Studio for the Mac runs great on the M1 processor, I’m able to develop using a wide range of technology stacks, and I really like that I don’t hear my fan start to run every time I start a docker image.