📜 ⬆️ ⬇️

Preparing an ASP.NET 5 (Core) project and DNX environment to participate in the hackathon as part of hack.summit () 2016 at Koding.com

My friend and I decided to participate in the world hackathon, held as part of hack.summit () 2016 . On Habré there is an article dedicated to this event.

The rules on the site said that the final project should be located on the Coding virtual machine, and everything would be fine, but only here Coding's platform uses Ubuntu as the operating system, and we write on Microsoft technologies. There was a question of not participating or testing asp.net 5 on coreclr. We chose the second and began a closer acquaintance with the innovations that appeared in this version.

On the Microsoft site, in general, a clear instruction was given on how to install dnx for Linux (fortunately for Ubuntu April 14, 2004), although I had to deal with some problems, as they say, “the first pancake is a lump”, so I would like to give below the sequence of steps that led to the working result.
')


The first step is to install curl:

sudo apt-get install unzip curl 

The second step is to install the .NET Version Manager:

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

The third step is installing the necessary DNX packages:

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

The fourth step is to install DNX for .NET Core:

 dnvm upgrade -r coreclr 

Next in the maykrosoftovskoy instructions installed mono, but we used coreclr, so skip this step.

The fifth step is to install libuv (required for running Kestrel):

 sudo apt-get install make automake libtool curl curl -sSL https://github.com/libuv/libuv/archive/v1.8.0.tar.gz | sudo tar zxfv - -C /usr/local/src cd /usr/local/src/libuv-1.8.0 sudo sh autogen.sh sudo ./configure sudo make sudo make install sudo rm -rf /usr/local/src/libuv-1.8.0 && cd ~/ sudo ldconfig 

If everything went without errors, we should see the only installed version of .Net:

 dnvm list 


Here I want to make a remark, when working in Visual Studio, the necessary version of .Net constantly flew in me and, perhaps, because of this, the build hung when another version was assigned to the project properties. To fix this, you can run the following commands:

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



The sixth step , you need to somehow make available publishing on the target machine. You can simply drag`n`drop for dragging files on the Coding page, but we decided to do it via FTP. By the way, to send the final version of the project on the hackathon, I had to use the first option, because due to the tradition of uploading everything at the last moment, the FTP client could not connect to the server. In order not to complicate things, Coding suggests using your package manager and opening ftp in two lines:

 kpm install ftp 

The second line will change the password of the user of the virtual machine. The IP address of the server can be viewed in the machine properties on the Coding page.

In the user's folder there is a Web folder with sample files, delete them and create in their place the folder ASP.Net where the project will be located.

The next difficulty that arises is that at the time of participation in the hackathon, Entity Framework 7 did not have the implementation of the EntityFramework.MicrosoftSqlServer package for Linux, so it was necessary to use alternatives to MS SQL Server. Help EF offers to use SQLite for this purpose, therefore

Seventh step , install SQLite:

 sudo apt-get install libsqlite3-dev 

The eighth step is to prepare the project in Visual Studio.

Create an ASP.NET Web Application template, choose ASP.NET 5 -> Web Application template, Individual User Accounts authentication.
Edit the project.json file by adding SQLite and deleting the extra, and also remove the dnx451 framework:

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

In the Startup.cs file in the ConfigureServices method, we delete what is related to SQL Server and add what we need for SQLite:

 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 in project.json they removed unnecessary things like IISPlatformHandler and BrowserLink.Loader, then you also need to clean the Configure method from calling extra middleware.

The ninth step is to upload the files of the prepared project from the src folder to the folder on the Coding server. We will keep the node_modules and wwwroot \ lib folders as we will load these dependencies using npm and bower on the destination server.

Tenth step . Node.js in the virtual machine is already there, so you can immediately install bower and fix some problems with running the packages, and in the site folder we will execute the commands needed to restore the packages:

 sudo ln -s /usr/bin/nodejs /usr/bin/node sudo npm install bower -g npm install bower install 

Eleventh step . The database will be located in the site directory and, according to the configuration in Startup.cs, called site.db. Migrations for it were generated by VS automatically, you can use them, or you can do it all over again. For the purity of the experiment, delete the Migrations folder and add them again along with the creation of the database file.

when I first tried to start dnu, I got an error
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 the third step, I did not press "Y" when downloading and installing packages.

 dnu restore dnu build --quiet dnx ef migrations add NewOne dnx ef database update 

The Kestrel server, which runs the asp.net site, runs by default on the 5000m port, Mykrasoft recommends that it does not shine into the network, but to use a proxy, Apache is already installed on the virtual machine, so we will use it for this purpose.

In the twelfth step, configure Apache:

 cd /etc/apache2/sites-enabled sudo nano 000-default.conf 

In it we leave only what we need.

 <VirtualHost *:80> S<VirtualHost *:80> # Rewrite scheme to ws otherwise apache can't do a websocket proxy RewriteEngine on RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC] RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC] RewriteRule .* ws://localhost:3000%{REQUEST_URI} [P] # Proxy ProxyRequests On ProxyPass / http://localhost:5000/ ProxyPassReverse / http://localhost:5000/ ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 

Restart Apache and, if everything is correct, when we try to open the site in the browser, we see “Service Unavailable”:

 sudo /etc/init.d/apache2 restart 

The thirteenth, the most successful step - launching the site. In the site directory, run the dnx web and see how Kestrel started 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 the fifth step, I inserted all the commands into the console at once and something did not work or the “Y” button was not pressed.

When everything starts, you can open the site and see how requests run in the console.



The site opens, you can register - it means the database is working.

You can start working on the project.

Source: https://habr.com/ru/post/278571/


All Articles