Getting Started with ASP.NET 5 on OSX

ASP.NET 5 is something special. We can build cross platform Web apps using .NET Core that run on OSX, Linux and Windows. But how do you get started on OSX? This post shows how quickly you can get up and running.

Dan Wahlin, Ward Bell and I are hosting an ASP.NET 5 workshop at DevIntersections / Anglebrackets in Las Vegas in Novemxber. Use promo code PAPA to get $50 off the event and come visit us. Registration will open in early June.

Here are some commands you should get familiar with:

  • dnvm is the .NET version manager. You'll run this occasionally to update your versions
  • dnu is the .NET package updater. This can update nuget packages and can also help update npm and bower packages via project.json.

  • dnx is the .NET execution runtime. You'll use this to run your app

Installation

First, start with getting the tools you need so you can run ASP.NET. The first step is to install homebrew, which is like Walmart for OSX. Homebrew makes it easy to download and install ton of great software libraries and tools. We'll use this to install and setup ASP.NET.

  1. Install homebrew by entering this at a terminal
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  2. Use homebrew to get ASP.NET
    brew tap aspnet/dnx
    brew update
    
  3. Add the following to the ~/.bash_profile or ~/.bashrc file. This makes it easy to use dnvm.
    source dnvm.sh
    
  4. Use homebrew to get the .NET version manager (dnvm) and upgrade the dnvm to the latest version
    brew install dnvm
    dnvm upgrade
    

And now you have ASP.NET 5!

File New Project

Creating a new project is easy with Yeoman. This is my preferred way to scaffold new projects on Mac or Windows. No more file new for me in the IDE!

There is a generator that the ASP.NET team helps curate named generator-aspnet. This is a good starting place, though I and many others will also be creating generators too.

  1. Install yo and gulp. You will use yo to run the generator and gulp to help automate tasks.
    npm install -g yo gulp
    npm install -g generator-aspnet
    
  2. Install the ASP.NET generator and run it with the gulp option. This generators a project using gulp, instead of grunt.
    yo aspnet --gulp
    
  3. Choose your project type. Web API Application, Empty Web, Console, or MVC Web App.
  4. run the app

    dnx . kestrel
    

    When you modify the packages list in project.json you should run dnu restore to get the latest ones.

    Enjoy!