In the past when doing .NET development, I’ve typically relied on running a Windows virtual machine inside VMware Fusion. This is still a good option, but nowadays it is possible to develop .NET applications on Mac OS without the use of a virtual machine. In today’s short post we’ll go over the setup required to do so.
What will our development environment consist of?
The typical .NET setup makes use of .NET (duh), SQL Server and some sort of IDE. Today we’ll be installing the following:
- SQL Server (inside Docker).
- The .NET Core SDK.
- Visual Studio Code.
Other than the SQL Server setup which is a little involved, the above will be a snap… let’s get at it!
Installing SQL Server
In order to run SQL Server on a Mac, we’ll need to run it from within Docker. So our first step will be to install Docker.
Installing Docker
The Docker installation is straight forward, just download and install the Mac version of Docker Desktop. Note:you’ll need to sign up for a Docker account in order to download the installer .
Once you’ve downloaded and installed Docker Desktop, launch Docker and you’ll see it running in your menu bar.
With Docker installed we can now move onto installing SQL Server.
Installing SQL Server inside Docker
We have a number of terminal commands available now that Docker is installed; one of which is search
. We can use this to search for the image we need.
Terminal
Right off the bat we see the image we want:
We can download the image with the pull
command.
Terminal
Now we need to run the installer.
Terminal
The parameters are pretty self-explanatory, the only thing you might want to change is the name or the password value (you need to use a password that meets the SQL Server password policy).
Once the above command has run we can verify that SQL Server is running via docker ps -a
.
Terminal
We’re all good!
Accessing SQL Server
So how do we get at our database server now that it is installed and running? Basically the same as you would a normal local instance of the server. For instance I am partial to TablePlus. Connecting to the instance is pretty simple, just create a new SQL Server connection:
And fill in the appropriate connection details:
Note you don’t need to specify a database, TablePlus will prompt you to select one if you don’t fill in the database field.
And that’s all there is to it!
A few useful Docker commands
A couple of commands that you will likely find useful:
To stop the SQL Server instance.
Terminal
To start the SQL Server instance.
Terminal
Note: replace SqlServer
in the commands above with whatever you used for the --name
parameter when you installed SQL Server.
To uninstall SQL Server, first we need to remove the container (after stopping the container).
Terminal
And now we can also remove the image we used to install SQL Server.
First we need to list our images.
Terminal
And then we can remove the image by passing in the IMAGE ID
value from above.
Terminal
OK, that’s all the Docker and SQL Server we need to deal with… onwards and upwards!
Installing .NET Core
Installing .NET Core is a snap, just download and run the SDK installer.
After doing so, you should be able to run the dotnet
command from a terminal window, i.e.
Terminal
That’s it, IDE time!
Installing Visual Studio Code
My editor of choice these days is Atom, but Visual Studio Code seems to be very popular and when it comes to developing .NET applications it stands to reason that a Microsoft product is likely to provide the best experience.
Installation is straight forward, just download the installer and let ‘er rip.
Configurating Visual Studio Code
There are a few configuration / setup steps that I found were helpful when setting up Visual Studio Code on my machine.
Add the executable to PATH. This allows you to open VSC via the terminal which can be useful for opening a specific directory or the current directory, i.e.
Terminal
To get this working, open the command palette (View -> Command Palette, or Cmd-Shft-P) and type shell
. You’ll see an option to “Install ‘code’ command in Path”.
Select the above and you’re good to go.
Getting the integrated terminal working. VSC has an integrated terminal window but I wasn’t initially able to get it working, an error message would flash up in the terminal window it would crash and then I’d get the following dialog.
For some reason when the terminal window was opening it was attempting to cd
into a directory that did not exist.
A bit of Googling yielded the solution:
Go to user settings (Code -> Preferences -> Settings) and then search for terminal.integrate:cwd
.
One of the first items you’ll see is the start path value, edit it to a directory that actually exists and all will be well!
Summary
That’s it for setting up a .NET development environment on a Mac, pretty simple! … happy .NET’ing!