Getting Asp.Net vNext running on a Mac! Shazam


Shazam! Asp.Net vNext on a Mac![/caption]

ASP.Net  is making a huge comeback! With the  ASP.Net vNext the open source version of the .Net series, has opened up it's  framework to an entirely new web developer community .  The cool thing about this lean framework is you can get use ASP.NET in the comfort of your Mac. In this tutorial , I will be going through  the tools and frameworks you need to get  ASP.NET vNext running on OS X Yosemite.

To get started you will need the following software ,frameworks and package managers :

Before you get started installing the frameworks and PKGs you need to get ASP.NET vNext running, make sure that you have the latest version for Node and npm. Copy and paste the code below into terminal.

 node --version && npm --version


Check to see if you have git installed as well .

git --version

Install Yeoman

Yeoman is an open source sleek scaffolding tool that consists frameworks  that make it quick and easy to build web applications.  The neat thing about Yeoman is it combines several functions into one place, such as template generators which we are going to use to get the ASP.NET vNext up and running .

sudo npm install —global yo


Now that  Yeoman is installed the next step is to get our ASP.NET framework installed using the yeoman generator.

npm install -g generator-aspnet

For this examples I selected the the MVC Application. Once you have entered an appropriate name, the generator will take care of the rest.

Entername

Now that  MVC application all ready , navigate to the folder  notice the  model, view and control are all there.  Similar to what you find if you used the MVC model template in Visual Studio.

MVCModeliscreated

Before you can run your ASP.NET vNext in sublime there are still a couple of dependencies  that need to be installed.  A lot of tutorials I have read miss the  dependencies below but I encountered a lot of errors  when trying to configure the K commands.

Install Mono

In order to run  an ASP.NET vNext on a Mac and Linux environment you need Mono. Copy and paste the code below into your terminal.

git clone https://github.com/mono/mono.git

Install Homebrew

Homebrew is an open source software package management tool ; it enables you install all the stuff you can't directly install in terminal out of the box. To install Homebrew you will need to copy and paste the Ruby code below.

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


Now, that Homebrew installed make sure to install all the extra mono dependencies.

brew install autoconf
brew install automake
brew install libtool


Install the ASP.NET vNext  Tools

brew tap aspnet/k
brew install kvm

InstallingKVM

It is important to note that in the current version of Asp.Net vNext Kestrel doesn’t come with it out of the box. So  in this case since I am  using the "Kestrel": "1.0.0-alpha4. To find out which version of  Kestrel you are running, open your project.json file in your Asp.Net project.  To install Kestrel copy and paste the code below.

kvm install 1.0.0-alpha4

Setting up your project in Sublime

Since this is possibly the first ASP.NET project you will need to install the Kulture as instructed in here using the package control plugin. If you have some issues with these steps, you can install it manually using the following steps:

  • Open your project in sublime
  • Click view
  • Click show console and copy and paste the python code below
    import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

With Kulture installed you will be able to run you ASP.NET project successfully.  To check to make sure that everything is working, try adding a new namespace into your HomeControllers.cs file.  If everything is in place you will notice the intellisense is in working.

intellsense

Steps to running your project

  • In sublime enter Cmd + Shift + p
  • Type K and  select run K Command
  • Select kpm build
  • Select k kestrel - If everything has installed correctly the server  should start

    Running the localhost server
  • Navigate  http://localhost:5004/

    ASPNET

For more information on  my Microsoft + Open source series please check out marianaggaga.com


Comments (4)

  1. Vaclav Elias says:

    What would be the steps to take an advantage of this glory and code Asp.Net vNext in Xamarin (already installed)? Should be the Mono step excluded? Or exactly same steps but as an editor would be just Xamarin? Thanks 🙂

  2. Steve Gentile says:

    Just fyi – prior to running the server, I cd into MvcApplication (default name) and ran kpm restore  after that I was able to run k kestrel – had it running on http://localhost:5004/

    Thanks!

  3. Satyam Kumar says:

    I am getting this strange error, please tell me where i am going on wrong ???

    Startup.cs(1,17): error CS0234: The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

  4. CXM says:

    I keep getting this error

    System.IO.IOException: Too many open files

     at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0

     at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) [0x00000] in <filename unknown>:0

     at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,System.IO.FileOptions)

     at Microsoft.AspNet.FileProviders.PhysicalFileProvider+PhysicalFileInfo.CreateReadStream () [0x00000] in <filename unknown>:0

     at Microsoft.AspNet.Mvc.Razor.RazorPreCompiler.GetCacheEntry (Microsoft.AspNet.Mvc.Razor.RelativeFileInfo fileInfo) [0x00000] in <filename unknown>:0

     at Microsoft.AspNet.Mvc.Razor.RazorPreCompiler.OnCacheMiss (ICacheSetContext cacheSetContext) [0x00000] in <filename unknown>:0

     at Microsoft.Framework.Cache.Memory.CacheExtensions+<>c__DisplayClass7_0`1[Microsoft.AspNet.Mvc.Razor.PrecompilationCacheEntry].<Set>b__0 (ICacheSetContext context) [0x00000] in <filename unknown>:0

     at Microsoft.Framework.Cache.Memory.MemoryCache.Set (System.String key, IEntryLink link, System.Object state, System.Func`2 create) [0x00000] in <filename unknown>:0

Skip to main content