Visual Studio For Mac Web Development

During Build 2015 Microsoft announced a bunch of new tools aimed at helping developers build cross platform applications. Amongst the announcements, they let us know that ASP.NET was now available and ready to run on Mac and Linux natively.

Visual Studio For Mac Web Development

Up until this point there has been a few different ways to get .NET applications running on Unix systems but none of them were truly native or supported by Microsoft.

With this announcement and the release of Visual Studio Code—Microsoft’s cross platform development tool—you can now develop cross platform .NET applications on your favourite operating system.

The web development experience in Visual Studio for Mac hews much closer to its Windows counterpart in a new update. Web developers who update their copies of Visual Studio for Mac to the newest.

Today I will show you how to get started with setting up your .NET development environment on a Mac running Yosemite and show you how to build a Console and an ASP.NET MVC 6 call log application using Visual Studio Code and ASP.NET 5.

Feel free to download all the code from the Github repository if all you want to do is setup your local environment and not worry about writing all the application code.

Our tools

  • A Mac computer running Yosemite or above
  • Homebrew package manager
  • Node.Js
  • A Twilio Account and a Twilio Phone Number – Sign up for free!

Visual Studio For Mac Download

Setup

To get started we need to make sure all the necessary tools are installed. If you are running on a Mac and still don’t have Homebrew installed you’re missing out, so download and install it from brew.sh.

Once homebrew is installed we can go ahead and download .NET Version Manager. This will install everything we need in order to run .NET as well as some useful tools we will talk about briefly.

Visual Studio For Mac Os

When the installation completes the following will have been installed for you:

  • DNVM (.NET Version Manager): is a set of command line instructions which allow you to configure your .NET Runtime. We can use it to specify which version of the .NET Execution Framework to use.
  • DNX (.NET Execution Framework): is the runtime environment for creating .NET applications for Windows, Mac and Linux.
  • DNU (.NET Development Utility): is a set of command line tools that allow us to build, package and publish projects created with DNX.

Make sure that all DNVM goodies are available on your terminal instance by running source dnvm.sh. For any future instances just run the following to permanently add it to your bash profile or equivalent according to your environment.

Let’s go ahead and check that DNVM is actually installed by running the following:

If you see a screen like the above you know you have DNVM properly installed, so let’s install the latest version of DNX.

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:

  1. Download a free Windows image. (at the time of writing, an ISO of Windows 10 can be downloaded from microsoft.com).
  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 Keystrokes’ (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 for 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 could be downloaded). Keep the installation as minimal as possible, i.e. just the Web Development component.
  9. 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.
  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 hook up your Mac host’s text-editor to your solution so you can rapidly edit → build:

  1. Set your VM network to ‘Bridged Adaptor’ and Promiscuous Mode to ‘Allow All’ (Devices → Network → Network Settings).
  2. 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.
  3. 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.).
  4. 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:

Studio
  1. Disable Windows's 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.
Visual

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.

Like This Article? Read More From DZone

Download Visual Studio For Mac

visual studio ,web dev ,.net development

Visual Studio For Mac Professional

Published at DZone with permission of Jonathan Conway . See the original article here.

C++ Visual Studio Mac

Opinions expressed by DZone contributors are their own.