TopMenu

Building Hosting Asp.net vNext app on Macbook

Note: This post is outdated and not applied to current version of Asp.net DNX version. 

In previous post we have learned how to start using the new Asp.net 5 hosting environment named “K” without using IIS. In this article we’ll learn how to start developing Asp.net web application on Macbook. As Microsoft announced the OSS of .Net technologies mean one should be able to contribute/create/host apps across platform including Linux, Max and Windows.

Background

The overview of developing and deploying cross platform of Asp.net web app really exciting thing coming with vNext. One can develop and deploy on any platform they want. I tried to create a picture representing Idea of cross platform develop/deploy.
image
In above picture the interesting part is Azure gives you an opportunity to create Linux based Virtual Machine. And visual studio enables the deployment and hosting your Asp.net Web app directly from new Visual Studio 2015. Isn’t it interesting?

Get started

Let start with instructions of how to create/run Asp.net on a Mac machine. Though all the steps are already specified on Asp.net github page but to give you more clearer picture of steps with screenshot would definitely help one to step ahead having hands on.
To install KVM (Kruntime** Version Manager) and the correct version of Mono on OS X using Homebrew follow the following steps:
**Note: Kruntime is code that bootstraps and runs an ASP.NET vNext application. This includes things like the compilation system, SDK tools, and the native CLR hosts.
Step 1 -
Install Homebrew if it is not already installed.
Run following command on terminal to install Brew via terminal:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/homebrew/install/master/install)"
image
Here you need to press Return key. You’ll see following output:
image
Here you need to insert the password of user you logged-in with.(Make sure user have Administrative rights). Also the cursor will not show you anything when you type password so just type and press Return key and the homebrew will be installed on your machine.
image
Step 2:
Run command brew tap aspnet/k to tap the ASP.NET vNext related git repositories. If you had already tapped the repo for previous releases, run brew untap aspnet/k to delete the old commands and tap again to get the updated brew scripts.
 image
Step 3:
Run command brew install kvm to install KVM. This also automatically install the latest KRE package from https://www.nuget.org/api/v2 feed.
image
Step 4:
Run command source kvm.sh on your terminal if your terminal cannot understand kvm.
Step 5:
Run command kvm upgrade. This will install the latest version of Kruntime. Now you’re ready with your Kruntime to host and run Asp.net vNext apps. Now to start with creating applications you would need an Editor. In this tutorial I’m going to use the Sublime Text 3. Download and install if it’s not already install on your macbook.
Step 6: Setting up Asp.net and C# plugin for Sublime
Omnisharp have developed many plugins for several famous editors for various platforms. So in order to setup an development environment I have to install the Omnisharp plugin for Sublime. Follow the instructions to make the sublime Asp.net and C# development ready with similar experience as we have in Visual studio.
imageimage
Step 7: Getting a solution ready in Sublime text editor.
If you want to start with creating a fresh .Net solution then follow the blogs post here. The post will show you how to create a sublime project and convert it into the Asp.net vNext project.
In this post I’ll just use the sample solutions which are already there on Asp.net home branch to save some time for me and you. Install Github for OSx if it’s not already installed. Now clone the home branch from the terminal by running the following command:
image
Open the project Hello Mvc in the Sublime to check if your color scheme, Language and Intellisense settings are done correctly.
SNAGHTML3e04c94c
Step 8: Building and Restoring the nuget packages of downloaded samples
Run kpm restore command from terminal. This will restore the nuget packages required to build the project. Make sure you navigate to the directory where the project resides before running the command.
image
Now your first sample web is ready to host and run on Mac.
Step 9: Hosting and running sample web
Run command k kestrel. This command will build and host the Asp.net web app on mac. The default port where the application will be running is http://localhost:5004. This is configuration from project.config file. I’ll be writing another post about the new Asp.net vNext project structure and configurations.
image
SNAGHTML3e1b87da
If you see any build errors in code you can open the web application in Sublime editor and fix the build errors if there are compilation errors. To build the Asp.net from web first change the setting in the Project menu item. Change the Build System to Asp.net.
image
Fix the compilation errors and build the project using command + B.
SNAGHTML3e1f4eb2
That’s all. Happy coding!!!
If you have any questions/doubts or feedback about the article feel free to drop comments below.

1 comment:

  1. Wow, really very nice information for me. Thank you very much. Here I found some information about the Background of Asp.net next app on MacBook. Learn a lot here. I have recently hosted my site from myasp.net. If I needed than used your technique….

    ReplyDelete