ASP.NET vNext application under Ubuntu

I want to talk about my experience in deploying ASP.NET vNext under Ubuntu 14.04. I myself have been developing for Windows for a long time and, if I had any business with Unix systems, it is casual and invisible to me and Unix systems. But, despite this, the news about the transfer of the .Net part to OpenSource with Unix support pleased me as an occasion for further development and expanding the boundaries of knowledge.

As a result of brief torment and research of various forums and issue trackers, I managed what seemed previously unthinkable. Code written in C #, which runs in an environment invented and developed in MS, which is an ASP.NET MVC application (!) Earned.

First you need to download and install the OS itself. I took the image from the official site.

http://www.ubuntu.com/download/desktop/contribute/?version=14.04.1&architecture=amd64


Next, I deployed this image to VirtualBox, because it was just an experiment.

To run the application on ASP.NET vNext under Ubuntu, we need two things: a project designed in the new ASP.NET vNext style and deployed and launched KRuntime with the ability to raise the Kestrel web server.

Application creation


The first task is solved simply. You can take a ready-made very simple example from the github:

https://github.com/aspnet/Home/tree/master/samples/HelloWeb.

If the git has not yet been installed, install it:

sudo apt-get install git

Then we clone a repository with examples:

git clone https://github.com/aspnet/Home.git


Infrastructure


The second task is more difficult, but also solvable. The process consists of the following steps:

  1. Mono Installation

    wget http://download.mono-project.com/repo/xamarin.gpg
    sudo apt-key add xamarin.gpg
    echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee --append /etc/apt/sources.list.d/mono-xamarin.list
    sudo apt-get update
    sudo apt-get install mono-complete
    

  2. Install KRuntime

    We allow kvm to climb their sites according to their certificates.
    sudo certmgr -ssl -m https://go.microsoft.com
    sudo certmgr -ssl -m https://nugetgallery.blob.core.windows.net
    sudo certmgr -ssl -m https://nuget.org
    mozroots --import --sync
    

    Download the kvm installation script and run it, then run kvm upgrade. Now all we need is already installed:

    curl https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.sh | sh && source ~/.kre/kvm/kvm.sh && kvm upgrade
    

    We pull all the dependencies of KRuntime:

    kpm restore
    

  3. Bower Installation

    If NPM is not installed, install:

    sudo apt-get install npm
    

  4. Web server startup

    We compile libuv, and (hard hack), copy the assembly to the KRuntime folders, because there are incompatible versions by default, since MS has not yet worked on Linux support.

    KRuntime currently requires version 1.0.0-rc1 and KRuntime itself is in version 1.0.0-beta1. All this changes very quickly, so it is always necessary to know which versions were linked to each other for the last time. (The script was taken and slightly corrected from here ).

    wget http://dist.libuv.org/dist/v1.0.0-rc1/libuv-v1.0.0-rc1.tar.gz 
    tar -xvf libuv-v1.0.0-rc1.tar.gz
    cd libuv-v1.0.0-rc1/
    ./gyp_uv.py -f make -Duv_library=shared_library
    make -C out
    sudo cp out/Debug/lib.target/libuv.so /usr/lib/libuv.so.1.0.0-rc1
    sudo cp out/Debug/lib.target/libuv.so ~/.kpm/packages/Microsoft.AspNet.Server.Kestrel/1.0.0-beta1/native/darwin/universal/libuv.dylib
    sudo ln -s libuv.so.1.0.0-rc1 /usr/lib/libuv.so.1
    

    All work with KRuntime is performed on the application, so we should be in the project directory where project.json is located. In our case, we do:

    cd Home/samples/HelloWeb/
    


    We launch our application on the kestrel server (all settings in the project.json file):

    k kestrel
    

    Open the browser and go to the address:

    http://localhost:5004
    

    Well, or another address specified in project.json next to kestrel:

The process is very unusual, a lot has changed, but the development itself pleases. It is also pleasant that the restrictions are becoming less and the boundaries are erased.

Also popular now: