Codementor Events

.NET development on MacOS

Published Jun 07, 2017Last updated Aug 02, 2017
.NET development on MacOS

Originally published on conwy.co

Hats off to Microsoft for releasing the new Visual Studio for Mac.

Unfortunately this does not, at present and in all cases, enable us to properly develop .NET web applications on a Mac. Many projects can only be built on a Windows operating system. (E.g. projects requiring libraries that can’t easily be ported, such as the SyncFusion Excel libraries, which utilise Microsoft Office InterOp).

I managed to get around this on a recent project by hosting my .NET stack in VirtualBox, while using my MacOS for development using my favourite Mac text editor and Terminal. The following are some steps you can take to reproduce a similar setup on your Mac.

Firstly, let’s set up a VM to run your solution:

  1. Download the free Windows image.
  2. Create a VirtualBox VM. (Choose a Dynamic VHD and make it 80 GB. You’ll need the capacity. Also, to prevent freeze-ups, reduce max CPU consumption to 80%. Finally, for performance, increase memory to at least 50% of total memory, assuming 8 GB of total machine memory.)
  3. Turn off ‘Autocapture Keystokes’ (VirtualBox Preferences → Input). This makes it easier to CMD-tab between your VM and your text editor, e.g. when running MSBuild.
  4. Install Windows. Make sure you set a password on your user account. This will help when it comes time to create a network share.
  5. Install VirtualBox Extensions.
  6. Configure display to the lowest resolution (Display settings) for performance. (You might also want to apply a faster-rendering theme to Windows. I found Classic Shell from IvoSoft did this quite nicely.)
  7. Install IIS.
  8. Download and install Visual Studio. (At the time of writing, a free community edition of Visual Studio can be downloaded.) Keep the installation as minimal install possible, i.e. just the Web Development component.
  9. Install SQL Server Express. (At the time of writing, the Express edition can be downloaded for free.) Again, keep it minimal. Just the engine and Management Console.
  10. Using Visual Studio, check out your solution into a project folder on your VM.
  11. Open your solution in Visual Studio, build. Then go into your project properties and set it up in ‘Local IIS’, in the root (delete the text after ‘localhost/’).
  12. Open IIS and check that everything is working and your solution is being served locally.

Secondly, let’s use Resilio Sync to keep your source files synced between your Mac host and your Windows VM. This will enable you to rapidly edit → build, using the VM for build only, but being able to do everything else (e.g. use version control tools) in the host.

  1. Download and install Resilio Sync into your VM.
  2. Add the folder where your source code is kept in you VM to Resilio Sync.
  3. Likewise, download and install Resilio Sync on your Mac host.
  4. Use the 'Enter a key or link' feature to link to the folder on your VM.

Once everything has been copied over, you'll have a constantly (and, in my experience, rapidly) synced copy of your source folder on your Mac host. Since Resilio copies all files, byte-for-byte, everything including your version-control repository (e.g. ./git folder) will be copied. This means you can work with version control tools as if you were directly connected to the VM. This setup gave me the best experience, with no perceived difference between editing on the host vs. editing in the VM.

Thirdly, let’s connect to your running website from your Mac host’s browser, so you can rapidly edit → build → refresh:

  1. Disable Windows Firewall. (Control Panel → System and Security → Windows Firewall → Turn off)
  2. Find out the computer name in your VM. (Control Panel → System, look under Computer name)
  3. Now, in your Mac host’s browser, navigate to: http://<computer-name>.local/. This should serve up your solution hosted on IIS.

This should give you a reasonably productive setup, enabling you to switch between your Mac text editor, Mac web browser and VM running a Build command-line.

Coming soon: I even managed to get a Mac SQL Server client working with this set-up. I will add instructions for this in the near future.

Discover and read more posts from Jonathan Conway
get started
post commentsBe the first to share your opinion
Jaime Rubio 👨🏻‍💻
6 years ago

Hi Jonathan, thanks for such a great article in the subject! 👏

I’ve almost everything up and running, but couldn’t load the solution in my mac chrome browser.

My solution deploys 2 projects, one at localhost:3411 and the other at localhost:3456 (one is for the web layer and the other for the services layer). I tried both http://<computer-name>.local:<port>/ and http://<computer-name>.local/. Could you please help me with this? Thanks in advance

Show more replies