ASP.NET Core MVC Web App on Raspbian ARM32

.NET Core allows you to develop ASP.NET Core web apps that can run on Windows, macOS and
Linux. With a bit of configuration you can even get it running on the ARM32 processor architecture of the raspberry pi 3.

The first step is to install the .NET Core SDK wherever you want your development environment to be. The SDK will not run on the pi so you will have to do your development in a different environment (which is preferable anyway given the pi's hardware).
https://www.microsoft.com/net/download/windows

.NET Core development flows a bit differently than most people work with the standard .NET Framework. Many important development processes are executed via the command line. In windows, open the command prompt (cmd.exe) and type dotnet -h to verify that you have at least version 2.0 installed on your machine.

To create a starter ASP.NET MVC project from a template, type dotnet new mvc at your preferred directory to create the project files.

One code change is necessary to connect the app to the network interfaces on the pi. Add the UseUrls() method call to the Program.cs file as shown here:

public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseUrls("http://*:8000")
                .UseStartup<Startup>()
                .Build();
    }

Since .NET Core is cross-platform, it is important that you build your applications for your target environment's architecture. For the pi, use dotnet publish -r linux-arm which will product output files that are compatible with the pi inside the bin directory.

Believe it or not, at this point you have everything you need in terms of a deliverable example app. The next step is to set up the pi to run it.

At the linux terminal, type sudo apt-get update followed by sudo apt-get install curl libunwind8 gettext apt-transport https. Next use curl -sSL -o dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Runtime/release/2.0.0/dotnet-runtime-latest-linux-arm.tar.gz to download the latest .NET Core Runtime for ARM32
sudo mkdir -p /opt/dotnet
sudo tar zxf dotnet.tar.gz -C /opt/dotnet
sudo ln -s /opt/dotnet/dotnet /usr/local/bin
Use dotnet --help to test the installation.
The pi is now ready to run the application, so we need to transfer it over.

I chose to use WinSCP for transfer of the publish directory to my pi's desktop. Find the IP address of the pi using a command such as ip addr or ifconfig. You also need to know your username and password for the pi, which by default are pi and raspberry. Lastly, make sure you start the ssh process via sudo /etc/init.d/ssh start so that you can connect.

Lastly set the permission on the main dll in the publish directory with sudo chmod 755 ./appname. You can now start up the app with ./appname!

This will start up the kestrel web server process. At this point you can now go to localhost on the pi and you should see the basic starter project for an ASP.NET Core web app.

A good practice for development projects is of course to use some form of source control. For this project I initialized a repo with git for windows and pushed it to github. You can use a .gitignore to ignore the bin and obj directories which aren't necessary for development. To create a .gitignore on windows I had to create a text file first and then use cmd.exe ren gitignore.txt .gitignore. I added the directories to the file and committed, then pushed to the remote.

Useful resources:

https://samhobbs.co.uk/2015/01/dynamic-dns-ddclient-raspberry-pi-and-ubuntu

https://support.google.com/domains/answer/6147083?hl=en

https://www.raspberrypi.org/learning/networking-lessons/rpi-static-ip-address/

Comments

  1. In most circumstances, you'll use a pointer to play slot video games on the desktop version – a mouse. You will use your mouse to click and modify the number of paylines, the wager measurement, and then click the spin button to play. However, you will need to use your fingers to play on the cellular slots by hitting the screen within the applicable 카지노 areas. Some gamers may take issue with this distinction – however most gamers really couldn’t care less about it lengthy as|so lengthy as} the main slot experience is similar. Mr Vegas provides greater than 2,000 on-line on line casino video games, including slots, blackjack, roulette, video poker, reside on line casino and scratchcards.

    ReplyDelete

Post a Comment

Popular Posts