Linux: Mono 3.8.10 mit ASP.NET vNext
Was wäre, wenn man mit der Aktuellen .NET und ASP.NET Version arbeiten würde um z.b. Moderne Webservices mit der ASP.NET WebAPI zu erstellen oder bequem Webseiten mit ASP.NET MVC zu erstellen.
Was wäre, wenn dies auf einmal auch unter Linux funktionieren würde?
Ich denke wir würden dies alle ziemlich innovativ und toll finden oder? 😉
Mit ASP.NET vNext geht Microsoft den Weg eine „Core-CLR“ zu bauen um darauf Cloud-Optimiert ASP.NET Anwendungen laufen zu lassen.
Das schöne hierbei ist das diese CLR von Mono unterstützt wird und unter Linux betrieben werden kann.
Nachfolgend eine Anleitung wie man mono und ASP.NET vNext ERFOLGREICH unter Linux zum laufen bringen kann.
Diese Anleitung beruht auf die Verwendung der Buildroot (v7.1) zum kompilieren der Software – sollte aber auch mit einem normalen Debian oder Ubuntu funktionieren.
WICHTIG!!! – Um mono Kompilieren zu können muss /proc innerhalb der Buildroot/chroot gemountet sein!!!
Als erstes gilt sowohl für die Buildroot als auch für Debian oder Ubuntu : Einmal das System aktualisieren!
# mount /proc
# apt-get update && apt-get upgrade
Für das kompilieren erforderliche Pakete können mit folgendem Befehl installiert werden:
# apt-get install gettext-base gettext
Mono
Mono kompilieren
Die jeweils aktuelle Mono-Version kann unter Mono-Projekt bezogen werden.
Ich benutze hier die zum Zeitpunkt des Blog-Eintrages aktuelle Version 3.8.10.
# cd /src
# wget http://download.mono-project.com/sources/mono/mono-3.10.0.tar.bz2
# tar -xvjf mono-3.10.0.tar.bz2
# cd mono-3.10.0
# ./configure --prefix=/srv/mono
# make get-monolite-latest && make
# make install
Mono testen
Um das frisch kompilierte mono zu testen, rufen wir es einfach mit dem Parameter „–version“ auf:
# /srv/mono/bin/mono --version
Als Ausgabe sollte nun folgendes erscheinen:
Mono JIT compiler version 3.10.0 (tarball Tue Oct 7 12:32:24 UTC 2014)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen
Da mono nun in /srv/mono kompiliert wurde, wollen wir den bin pfad in die PATH Variable aufnehmen:
# PATH=$PATH:/srv/mono/bin
Um Nuget benutzen zu können und Pakete Herunterladen zu können, müssen wir folgende Zertifikate importieren:
# certmgr -ssl -m https://go.microsoft.com
# certmgr -ssl -m https://nugetgallery.blob.core.windows.net
# certmgr -ssl -m https://nuget.org
# certmgr -ssl -m https://www.myget.org/F/aspnetvnext/
# mozroots --import --sync
Ist dies erledigt, können wir ASP.NEt vNext installieren
ASP.NET vNext
Grundinstalation
Folgende Pakete brauchen wir für die ASP.NET vNext Installation:
# apt-get install curl unzip automake libtool
ASP.NET vNext
Das ASP.NEt vNext aket wird hier heruntergeladen und in /home/aspnet gelegt.
# cd /src
# wget https://github.com/aspnet/Home/archive/master.tar.gz
# tar -xvzf master.tar.gz
# cp -a Home-master /home/aspnet
# cd /home/aspnet/
KVM Installieren
KVM steht für „K Version Manager“.
Mit ihm kann man verschiedene Versionen der ASP.NET vNext Runtime installieren und verwalten.
Nähere informationen zu KVM gibt es auf der KVM-Projektseite.
Um KVM zu installieren gibt es ein Installationsscript welches man via curl herunterladen kann und danach ausführt:
# curl https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.sh | sh && source ~/.kre/kvm/kvm.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2475 100 2475 0 0 9615 0 --:--:-- --:--:-- --:--:-- 12757
Downloading kvm as script to '/root/.kre/kvm'
=> Source string already in /root/.bashrc
Type 'source /root/.kre/kvm/kvm.sh' to start using kvm
KRE Installieren
KRE steht für „KVM Runtime Engine“.
Diese wird durch KVM installiert und wird als bootstrapper benutzt um die ASP.NET vNext Anwendungen laufen zu lassen.
Zur KRE gehören z.B. Kompiler-System, SDK-Tools und native CLR Hosts.
Um die Aktuell verfügbare KRE zu installieren, führt man „kvm upgrade“ aus:
# kvm upgrade
Determining latest version
Latest version is 1.0.0-alpha4
Downloading KRE-Mono.1.0.0-alpha4 from https://www.myget.org/F/aspnetmaster/api/v2
Installing to /root/.kre/packages/KRE-Mono.1.0.0-alpha4
Adding /root/.kre/packages/KRE-Mono.1.0.0-alpha4/bin to process PATH
Setting alias 'default' to 'KRE-Mono.1.0.0-alpha4'
Um eine Liste der Installierten KRE-Versionen anzuschauen, gibt es den Befehl „kvm list“:
Active Version Runtime Location Alias
------ ------- ------- -------- -----
* 1.0.0-alpha4 Mono ~/.kre/packages default
LIBUV Installieren
Libuv ist eine Biliothek, welche man braucht um Kestrel benutzen zu können.
Kestrel ist ein „development web server for ASP.NET vNext und wird mit der KRE zusammen ausgeliefert.
In der Momentanen „Unix-Version“ der KRE ist jedoch nur die Libuv für MacOSX enthalten.
Versucht man Kestrel mit dieser Version der Libuv aufzurufen, bekommt man folgenden Fehler angezeigt:
System.NullReferenceException: Object reference not set to an instance of an object
Mit der folgenden Anleitung können wir uns eine Libuv für linux kompilieren:
# cd /src
# wget https://github.com/joyent/libuv/archive/master.tar.gz
# mv master.tar.gz libuv.tar.gz
# tar -xvzf libuv.tar.gz
# cd libuv-master
# ./automake.sh
# ./configure
# make
# make install
# mv /root/.kpm/packages/Microsoft.AspNet.Server.Kestrel/1.0.0-alpha4/native/darwin/universal/libuv.dylib /root/.kpm/packages/Microsoft.AspNet.Server.Kestrel/1.0.0-alpha4/native/darwin/universal/libuv.dylib_alt
# cp /usr/local/lib/libuv.so.1 /root/.kpm/packages/Microsoft.AspNet.Server.Kestrel/1.0.0-alpha4/native/darwin/universal/libuv.dylib
Damit haben wir eine Linux-Version der Libuv erstellt und diese in das Verzeichnis kopiert von dem Kestrel sie benutzt.
ASP.NET vNext Beispiele testen
Die ASP.NET vNext Beispiele liegen in unserem Beispiel im Verzeichnis „/home/aspnet/samples“.
Insgesamt liegen dort 3 Beispiel, ich möchte hier jedoch nur auf die „ConsoleApp“ und die „HelloMVC“ eingehen.
Um die Beispiele zum laufen zu bringen müssen mit dem Befehl „kpm restore“ die Abhängikeiten aufgelöst werden.
KPM steht für „K Paket Manager“, der parameter „restore“ löst die Abhängigkeiten entsprechend der „project.json“ Datei auf.
Nähere Informationen zu KPM gibt es auf der KPM Seite.
ConsoleApp
Das Beispiel „ConsoleApp“ ist eine einfache Konsolen-Anwendung, welche einfach ein „Hello World“ ausgibt.
Über „kpm restore“ werden die Abhängigkeiten aufgelöst und mit dem Befehl „k run“ die Anwendung aufgerufen.
# cd /home/aspnet/samples/ConsoleApp/
# kpm restore
...
Resolving complete, 30801ms elapsed
Installing System.Console 4.0.0.0
Installing System.Runtime 4.0.20.0
Installing System.IO 4.0.0.0
Installing System.Text.Encoding 4.0.10.0
Installing System.Threading.Tasks 4.0.10.0
Restore complete, 30830ms elapsed
# k run
Hello World
HelloMVC
Das Beispiel „HelloMVC“ ist ein MVC Beispiel, welches wir mit Hilfe von Kestrel starten wollen.
Als erstes werden via „kpm rstore“ die Abhängigkeiten aufgelöst und anschließend wird die Anwendung via „k kestrel“ gestartet.
Die Anwendung ist dann auf Port 5004 z.b. http://localhost:5004 verfügbar.
# cd /home/aspnet/samples/HelloMvc/
# kpm restore
...
CSharp/0.7.4091001-beta 4733ms
Resolving complete, 122052ms elapsed
Installing Kestrel 1.0.0-alpha4
Installing Microsoft.AspNet.Server.Kestrel 1.0.0-alpha4
Installing Microsoft.Framework.Runtime.Interfaces 1.0.0-alpha4
Installing Microsoft.AspNet.Diagnostics 1.0.0-alpha4
Installing Microsoft.AspNet.FeatureModel 1.0.0-alpha4
Installing Microsoft.AspNet.Http 1.0.0-alpha4
Installing Microsoft.AspNet.PipelineCore 1.0.0-alpha4
Installing Microsoft.AspNet.HttpFeature 1.0.0-alpha4
Installing Microsoft.AspNet.WebUtilities 1.0.0-alpha4
Installing Microsoft.AspNet.Hosting 1.0.0-alpha4
Installing Microsoft.Framework.DependencyInjection 1.0.0-alpha4
Installing Microsoft.AspNet.Security.DataProtection 1.0.0-alpha4
Installing Newtonsoft.Json 6.0.4
Installing Microsoft.Framework.ConfigurationModel 1.0.0-alpha4
Installing Microsoft.Framework.ConfigurationModel.Shared 1.0.0-alpha4
Installing Microsoft.Framework.Logging 1.0.0-alpha4
Installing Microsoft.Framework.Logging.Interfaces 1.0.0-alpha4
Installing Microsoft.AspNet.Server.WebListener 1.0.0-alpha4
Installing Microsoft.Net.WebSocketAbstractions 1.0.0-alpha4
Installing Microsoft.Net.Http.Server 1.0.0-alpha4
Installing Microsoft.Net.WebSockets 1.0.0-alpha4
Installing Microsoft.AspNet.Mvc 6.0.0-alpha4
Installing Microsoft.AspNet.Mvc.Common 6.0.0-alpha4
Installing Microsoft.AspNet.FileSystems 1.0.0-alpha4
Installing Microsoft.AspNet.Mvc.Razor.Host 6.0.0-alpha4
Installing Microsoft.AspNet.Razor 4.0.0-alpha4
Installing System.IO.FileSystem 4.0.0.0
Installing System.Threading.Thread 4.0.0.0
Installing Microsoft.AspNet.Mvc.ModelBinding 6.0.0-alpha4
Installing Microsoft.DataAnnotations 1.0.0-alpha4
Installing Microsoft.AspNet.Mvc.HeaderValueAbstractions 1.0.0-alpha4
Installing Microsoft.AspNet.RequestContainer 1.0.0-alpha4
Installing Microsoft.Framework.OptionsModel 1.0.0-alpha4
Installing Microsoft.AspNet.Mvc.Core 6.0.0-alpha4
Installing Microsoft.AspNet.Security 1.0.0-alpha4
Installing Microsoft.AspNet.Routing 1.0.0-alpha4
Installing Microsoft.AspNet.Mvc.Razor 6.0.0-alpha4
Installing K.Roslyn 1.0.0-alpha4
Installing Microsoft.CodeAnalysis.Common 0.7.4091001-beta
Installing Microsoft.Bcl.Metadata 1.0.12-alpha
Installing Microsoft.Bcl.Immutable 1.1.20-beta
Installing Microsoft.CodeAnalysis.CSharp 0.7.4091001-beta
Installing System.IO 4.0.10.0
Installing System.Collections 4.0.10.0
Installing System.Resources.ResourceManager 4.0.0.0
Installing System.ComponentModel 4.0.0.0
Installing System.Linq 4.0.0.0
Installing System.Diagnostics.Tools 4.0.0.0
Installing System.Threading 4.0.0.0
Installing System.Globalization 4.0.10.0
Installing System.Runtime.Extensions 4.0.10.0
Installing System.Diagnostics.Debug 4.0.10.0
Installing System.Reflection 4.0.10.0
Installing System.Reflection.Primitives 4.0.0.0
Installing System.Runtime.Handles 4.0.0.0
Installing System.IO.FileSystem.Primitives 4.0.0.0
Installing System.Security.Claims 1.0.0-alpha4
Installing System.Diagnostics.Contracts 4.0.0.0
Installing System.Security.Principal 4.0.0.0
Installing System.Runtime.InteropServices 4.0.20.0
Installing System.Globalization.Extensions 4.0.0.0
Installing System.Net.Primitives 4.0.10.0
Installing System.Security.Cryptography.X509Certificates 4.0.0.0
Installing System.Security.Cryptography.Encryption 4.0.0.0
Installing System.Security.Cryptography.Encoding 4.0.0.0
Installing System.Reflection.TypeExtensions 4.0.0.0
Installing System.Threading.ThreadPool 4.0.10.0
Installing System.Diagnostics.Tracing 4.0.10.0
Installing System.Diagnostics.TraceSource 4.0.0.0
Installing System.Collections.Concurrent 4.0.0.0
Installing System.Text.Encoding.Extensions 4.0.10.0
Installing System.Security.Cryptography.Hashing.Algorithms 4.0.0.0
Installing System.Security.Cryptography.Hashing 4.0.0.0
Installing Microsoft.Win32.Primitives 4.0.0.0
Installing System.Threading.Overlapped 4.0.0.0
Installing System.Threading.Timer 4.0.0.0
Installing System.Reflection.Extensions 4.0.0.0
Installing System.Text.RegularExpressions 4.0.0.0
Installing System.Linq.Expressions 4.0.0.0
Installing System.Reflection.Emit.ILGeneration 4.0.0.0
Installing System.Reflection.Emit.Lightweight 4.0.0.0
Installing System.Xml.XmlSerializer 4.0.0.0
Installing System.Runtime.Serialization.Xml 4.0.0.0
Installing System.Xml.ReaderWriter 4.0.10.0
Installing Microsoft.CSharp 4.0.0.0
Installing System.Security.Cryptography.RandomNumberGenerator 4.0.0.0
Installing System.IO.Compression 4.0.0.0
Installing System.Dynamic.Runtime 4.0.0.0
Installing System.ObjectModel 4.0.0.0
Installing System.Runtime.Serialization.Primitives 4.0.0.0
Installing System.ComponentModel.Annotations 4.0.10.0
Restore complete, 122935ms elapsed
# k kestrel
Started
Super! 🙂
Das war es nun auch schon.
Jetzt haben wir mono Installiert und können ASP.NET vNext Anwendungen unter Linux laufen lassen.
Ich denke mit diesen Vorraussetzungen können wir sehr optimistisch in die Zukunft blicken und auf ein größeres, Plattformunabhängiges .NET hoffen.
Login