.NET Development on Mac
Are a Mac user who wants to get into .NET development? Learn how to set up Visual Studio on our Mac and started with .NET!
Join the DZone community and get the full member experience.Join For Free
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 utilize 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 favorite 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:
- Download a free Windows image. (at the time of writing, an ISO of Windows 10 can be downloaded from microsoft.com).
- 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.
- Turn off ‘Autocapture Keystrokes’ (VirtualBox Preferences → Input). This makes it easier to CMD-tab between your VM and your text editor, e.g. when running MSBuild.
- Install Windows. Make sure you set a password for your user account. This will help when it comes time to create a network share.
- Install VirtualBox Extensions.
- 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.
- Install IIS.
- Download and install Visual Studio (at the time of writing, a free community edition of Visual Studio could be downloaded). Keep the installation as minimal as possible, i.e. just the Web Development component.
- Install SQL Server Express (at the time of writing, the Express edition could be downloaded for free). Again, keep it minimal. Just the engine and Management Console.
- Using Visual Studio, check out your solution into a project folder on your VM.
- 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/’).
- Open IIS and check that everything is working and your solution is being served locally.
Secondly, let’s hook up your Mac host’s text-editor to your solution so you can rapidly edit → build:
- Set your VM network to ‘Bridged Adaptor’ and Promiscuous Mode to ‘Allow All’ (Devices → Network → Network Settings).
- Now, share your project folder. In the Security tab, add ‘Everyone’ (ticking all boxes) and in the Sharing tab, click Share, give ‘Everyone’ Read/Write permissions. Turn on File and Printer Sharing.
- Connect to your shared folder from your Mac host. Finder → Network → Your VM computer name → Your shared folder. Copy the full path of that folder (it should look like: `/Volumes/foo/bar/…`) and keep it somewhere easy to access, e.g. a text file somewhere. You can now use this path to access the source files on your VM as if they were on your Mac host (e.g. `cd` to it in Terminal, open it in a text editor, etc.).
- Now, to keep things nice and fast, close everything on your VM except for a single instance of MSBuild Command Line. In this command line, `cd` to your project folder. You can execute `MSBuild` every time you need to rebuild. So now you can CMD-tab quickly between your text editor (Mac) and running `MSBuild` (Windows).
Thirdly, let’s connect to your running website from your Mac host’s browser, so you can rapidly edit → build → refresh:
- Disable Windows's Firewall (Control Panel → System and Security → Windows Firewall → Turn off).
- Find out the computer name in your VM (Control Panel → System, look under Computer name).
- 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.
Published at DZone with permission of Jonathan Conway. See the original article here.
Opinions expressed by DZone contributors are their own.