Building Hosting ASP.Net vNext App on Macbook

Background

This is an overview of developing and deploying across platforms of ASP.Net web apps. Really exciting things are coming with vNext. One can develop and deploy on any platform they want. I tried to create a picture representing the idea of cross-platform development and deployment.



In the preceding picture the interesting part is Azure gives you an opportunity to create a Linux based Virtual Machine. And Visual Studio enables the deployment and hosting of your ASP.Net Web app directly from new Visual Studio 2015. Isn't it interesting?

Get started

Let us start with instructions of how to create/run ASP.Net on a Mac machine. Though the entire procedure is already specified in the ASP.Net Github page, providing you a clearer picture of the procedure with screenshots should definitely help you to step ahead with a hands on experience.

To install KVM (Kruntime** Version Manager) and the correct version of Mono on OS X using Homebrew use the following procedure.

**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 the following command on the terminal to install Brew via terminal:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/homebrew/install/master/install)"



Here you need to press the Return key. You'll see the following output:



Here you need to insert the password of the user you logged-in with. (Be sure the user has Administrative rights). Also the cursor will not show you anything when you type the password so just type and press the Return key and the homebrew will be installed on your machine.



Step 2

Run the 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.



Step 3

Run the command brew install kvm to install KVM. This will also automatically install the latest KRE package from the https://www.nuget.org/api/v2 feed.



Step 4

Run the command source kvm.sh on your terminal if your terminal cannot understand kvm.

Step 5

Run the 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 creating applications you need an Editor. In this tutorial I'm going to use the Sublime Text 3. Download and install it if it's not already installed on your Macbook.

Step 6

Set up ASP.Net and the C# plugin for Sublime.

Omnisharp has developed many plugins for several famous editors for various platforms. So in order to set up a development environment I need 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.

Step 7

Get a solution ready in the Sublime text editor.

If you want to start with creating a fresh .Net solution then follow the blogs post here. The article will show you how to create a sublime project and convert it into the ASP.Net vNext project.

In this article I'll just use the sample solutions that 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:



Open the project Hello Mvc in the Sublime to check if your color scheme, Language and Intellisense settings are done correctly.



Step 8

Build and Restore the Nuget packages of the downloaded samples.

Run the kpm restore command from the terminal. This will restore the Nuget packages required to build the project. Be sure you navigate to the directory where the project resides before running the command.



Now your first sample web is ready to host and run on Mac.

Step 9

Now to host and run the sample web.

Run the 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 the configuration from the project.config file. I'll be writing another article about the new ASP.Net vNext project structure and configurations.





If you see any build errors in the code then you can open the web application in the Sublime editor and fix the build errors if there are compilation errors. To build the ASP.Net from the web first change the setting in the Project menu item. Change the Build System to ASP.Net.



Fix the compilation errors and build the project using command + B.



That's all. Happy coding!!!

If you have any questions/doubts or feedback about the article then feel free to drop the comments below.


Similar Articles