By `Steve Smith`_ | Originally Published: 30 April 2015
.._`Steve Smith`: Author_
ASP.NET 5 is cross-platform and can be developed and run on OS X as well as Linux and Windows. See how you can quickly install, scaffold, run, debug, and deploy ASP.NET applications on a Mac.
This article covers the following topics:
-`Setting Up Your Development Environment`_
-`Scaffolding Applications Using Yeoman`_
-`Developing ASP.NET Applications on a Mac With Visual Studio Code`_
First, make sure you have `installed ASP.NET on your Mac OS X machine </getting-started/installation/installing-on-mac/installing-on-mac>`_. This step will include installing `Homebrew <http://brew.sh/>`_ and configuring DNVM. This article has been tested with beta4. You can confirm that you are running the correct version of ``dnx`` by running the command ``dnvm list``. You should see ``default`` listed under the ``Alias`` column for ``1.0.0-beta4`` as shown:
Now, install Visual Studio Code from `code.visualstudio.com <http://code.visualstudio.com>`_. Unzip the application and open it - the first time you should see the a welcome screen:
To get started with your first ASP.NET application on a Mac, select File -> Open and choose the folder where you unzipped the empty web site (or scaffolded a site with Yeoman).
From a Terminal / bash prompt, run ``dnu restore`` to restore the project's dependencies. At this point, you should be able to host and browse to your simple ASP.NET web application.
This empty project template simply displays "Hello World!". Open ``Startup.cs`` in Visual Studio Code to see how this is configured:
If this is your first time using Visual Studio Code (or just *Code* for short), note that it provides a very steamlined, fast, clean interface for quickly working with files, while still providing tooling to make writing code extremely productive.
The Explore viewlet allows you to quickly navigate within the folder system, as well as easily see the files you are currently working with. It displays a badge to indicate whether any files have unsaved changes, and new folders and files can easily be created (without having to open a separate dialog window). You can easily Save All from a menu option that appears on mouse over, as well.
*Code* will integrate with Git if it is installed on your system. You can easily initialize a new repository, make commits, and push changes from the git viewlet.
The Debug viewlet supports interactive debugging of applications. Currently only node.js and mono applications are supported by the interactive debugger.
Finally, Code's editor has a ton of great features. You should note right away that several using statements are underlined, because Code has determined they are not necessary. Note that classes and methods also display how many references there are in the project to them. If you're coming from Visual Studio, Code includes many of the keyboard shortcuts you're used to, such as ``command k c`` to comment a block of code, and ``command k u`` to uncomment.
The sample we're using is configured to use Kestrel as its webserver. You can see it configured in the ``project.json`` file, where it is specified as a dependency and as a command.
It's not necessarily obvious, but if you want to stop the web server once you've started it, simply press ``enter``. If that doesn't work, you can press ``control + z`` and then type ``kill %1`` to kill the process.
We can update the application to output information to the console whenever a request is received. Update the ``Configure()`` method as follows:
..code-block:: c#
:linenos:
:emphasize-lines: 5
public void Configure(IApplicationBuilder app)
{
app.Run(async (context) =>
{
Console.WriteLine("Request for " + context.Request.Path);
Save the file and restart the web server. Make a few requests to the URL. You should see the request information output in the Terminal window (recall that most browsers will automatically attempt to request a ``favicon.ico`` file when making a request to a new domain):
Once you've developed your application, you can easily use the git integration built into Visual Studio Code to push updates to production, hosted on `Windows Azure <http://azure.microsoft.com>`_. First, if you haven't already done so, initialize git in the folder you're working in.
ASP.NET 5 and DNX support installation on Mac OS X. Developers can quickly install the necessary tools to get started, including Yeoman for app scaffolding and `Visual Studio Code <http://code.visualstudio.com>`_ for rapid lightweight editing with built-in support for debugging, git integration, and Intellisense.