Home .NET Preparing ASP.NET 5 (Core) project and DNX environment to participate in hack.summit() 2016at Koding.com

Preparing ASP.NET 5 (Core) project and DNX environment to participate in hack.summit() 2016at Koding.com

by admin

My friend and I decided to participate in the global hackathon held at hack.summit() 2016 On the hubre, there’s a article dedicated to this event.
The rules on the site said that the final project will be located on a virtual machine Coding, and everything would be fine, but the Coding platform uses as the operating system is Ubuntu, and we write on Microsoft technologies. There was a question of refusing to participate or testing asp.net 5 on coreclr. We chose the latter and started to get acquainted more closely with the innovations of this version.
On the site of Microsoft provides generally clear instructions how to install dnx for Linux (just for Ubuntu 14.04). Although I had some problems with it, as they say "the first sucker punch", so I would like to show below steps which lead to a working result.
Preparing ASP.NET 5 (Core) project and DNX environment to participate in hack.summit() 2016at Koding.com
First step – curl installation:

sudo apt-get install unzip curl

Second step – Installing the .NET Version Manager:

curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh source ~/.dnx/dnvm/dnvm.sh

Third step – Install the necessary packages for DNX :

sudo apt-get install libunwind8 gettext libssl-dev libcurl4-openssl-dev zlib1g libicu-dev uuid-dev

Fourth step – DNX installation for .NET Core:

dnvm upgrade -r coreclr

Next, the Microsoft instructions install mono, but we used coreclr, so we’ll skip this step.
Fifth step – installing libuv (necessary to start Kestrel):

sudo apt-get install make automake libtool curlcurl -sSL https://github.com/libuv/libuv/archive/v1.8.0.tar.gz | sudo tar zxfv - -C /usr/local/srccd /usr/local/src/libuv-1.8.0sudo sh autogen.shsudo ./configuresudo makesudo make installsudo rm -rf /usr/local/src/libuv-1.8.0 cd ~/sudo ldconfig

If everything went without errors, we should see a single installed version of .Net:

dnvm list

Preparing ASP.NET 5 (Core) project and DNX environment to participate in hack.summit() 2016at Koding.com

I would like to make a remark here, when working in Visual Studio, I was constantly losing the right version of .Net, and perhaps because of this hangs build when a different version is assigned to the properties of the project. To fix this, you can run the following commands :

dnvm alias default -a x64 -r coreclr 1.0.0-rc1-update1dnvm use default -p

Preparing ASP.NET 5 (Core) project and DNX environment to participate in hack.summit() 2016at Koding.com

By the sixth step. , we need to somehow make publishing to the target machine available. You can drag-and-drop the files on the Coding page to do that, but we decided to do it via FTP. By the way, we had to use the first option to submit the final version of the project at the hackathon because the FTP client failed to connect to the server because of the tradition to upload everything at the last moment. In order not to complicate things, Coding offers to use their package manager and open ftp in two lines:

kpm install ftp

The second line will change the user password of the virtual machine. The IP address of the server can be found in the properties of the machine on the Koding page.
In the user folder there is a folder Web with example files, let’s delete them and create in their place a folder ASP.Net, where the project will be located.
The next difficulty encountered was that at the time of the hackathon, Entity Framework 7 did not have an implementation of the "EntityFramework.MicrosoftSqlServer" package for Linux, so we had to use alternatives to MS SQL Server. EF Hulp suggests. to use SQLite for this purpose, so
Seventh step. , install SQLite:

sudo apt-get install libsqlite3-dev

Eighth step – Preparing a project in Visual Studio.
Create from the ASP.NET Web Application template, select the ASP.NET 5 -> Web Application template, authentication Individual User Accounts.
Edit the project.json file by adding SQLite and removing the dnx451 framework:

.."dependencies": {"EntityFramework.Sqlite": "7.0.0-rc1-final", ...}, ..."frameworks": {"dnxcore50": { }}...

In the Startup.cs file in the method ConfigureServices , delete the SQL Server stuff and add the SQLite stuff:

using Microsoft.Extensions.PlatformAbstractions...var path = PlatformServices.Default.Application.ApplicationBasePath;services.AddEntityFramework().AddSqlite().AddDbContext<ApplicationDbContext> (options => options.UseSqlite("Filename=" + Path.Combine(path, "site.db")));...

If you deleted stuff like IISPlatformHandler and BrowserLink.Loader in project.json, you should also clean up the Configure method from calling unnecessary middleware.
By the ninth step pour the files of the prepared project from the folder src into a folder on the Coding server. The folders node_modules and wwwrootlib will be kept, because we will load these dependencies with npm and bower on the destination server.
Tenth step Node.js is already in the virtual machine, so we can install bower right away and fix some problems with launching packages, and in the site folder we run the necessary commands to restore packages :

sudo ln -s /usr/bin/nodejs /usr/bin/nodesudo npm install bower -gnpm installbower install

Eleventh step The database will lie in the site directory and, according to the configuration in Startup.cs, will be called site.db. The migrations for it were generated by VS automatically, we can use them, or we can do everything over again. For the sake of purity of the experiment, let’s delete the folder Migrations and add them again along with creating the database file.

I got an error the first time I tried to start dnu
failed to locate libcoreclr with error libunwind-x86_64.so.8: cannot open shared object file: No such file or directory
and dnx refused to work at all, so in step 3, I didn’t press "Y" when loading and installing packages.

dnu restorednu build --quietdnx ef migrations add NewOnednx ef database update

Server Kestrel, which runs asp.net site, by default runs on port 5000 `m, Microsoft recommends not to shine it on the network, and use a proxy, the virtual machine is already installed Apache, so we will use it for this purpose.
By the twelfth step. Set Up Apache :

cd /etc/apache2/sites-enabledsudo nano 000-default.conf

We leave only what we need in it.

<VirtualHost *:80>S<VirtualHost *:80># Rewrite scheme to ws otherwise apache can't do a websocket proxyRewriteEngine onRewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]RewriteRule .* ws://localhost:3000%{REQUEST_URI} [P]# ProxyProxyRequests OnProxyPass / http://localhost:5000/ProxyPassReverse / http://localhost:5000/ErrorLog ${APACHE_LOG_DIR}/error.logLogLevel warnCustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost>

Restart Apache and if everything is correct, when you try to open the site in your browser you see "Service Unavailable":

sudo /etc/init.d/apache2 restart

Thirteenth, the luckiest, step – site launch. In the directory of the site run dnx web and see how Kestrel starts up in the console:

dnx web

I got an error here too :
System.DllNotFoundException: Unable to load DLL 'libuv': The specified module could not be found.

This means that in step five, I put all the commands into the console at once and something didn’t work or the "Y" button was not pressed.

When everything is up and running, you can open the site and watch the console run queries.
Preparing ASP.NET 5 (Core) project and DNX environment to participate in hack.summit() 2016at Koding.com
The site opens, you can register – so the database works.
You can start working on the project.

You may also like