A Quickstart for setting up .NET Core V3.1 or later on a RPi running Raspbian so as to be able to build and run .NET Core apps from the command line. Start with a Console app. An ASP.NET Core Web App is also run on the device.

Summary

We will download the .NET Core tar folder, expand it and place it on the SD card that hosts the Raspbian OS. Then when booted we open a terminal on the device and add the location of that folder to the system path. We then set an environment variable pointing to the same folder. We are then good to create .NET Core projects, and to build and run them from the command line.

Setup

Working on the RPi in a terminal and browser.

  1. Get the zipped folder at dotnet.microsoft.com/download/dotnet-core/3.1
    • In second column, first row under SDK 3.1.100 look for the Linux line:
      | Linux | Package manager instructions        | ARM32    ARM64     x64     RHEL 6 x64;       |
      Click on the ARM32 link in that line or above and accept the download.
      Make sure it’s the SDK download and not the Runtime. Its called dotnet-sdk-3.1.100-linux-arm.tar.gz
    • _ The download page tells us how to do it:
       mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-3.1.100-linux-arm.tar.gz -C $HOME/dotnet
       export DOTNET_ROOT=$HOME/dotnet
       export PATH=$PATH:$HOME/dotnet
      
  2. In the terminal
    • cd $Home/Downloads
    • Run the 3 commands as above.
    • cd /
    • Run dotnet ---versiondotnet —version. Get:
       > dotnet --version
       3.1.100
      
    • Make a new directory apps in your work area and cd into it.
    • Make a new project folder app1 and cd into it.
    • Run dotnet new console
      • This is to create a Console app that outputs “Hello World”
    • ls To see what was created.
    • Now lets try to run it. Note that dotnet restore is now not needed.
      • dotnet run
    • ⚽⚽⚽⚽⚽ WE ARE THERE! (Been here before!) ⚽⚽⚽⚽⚽
     > dotnet run
     Hello World!
    
  3. Explore the contents of the folder by copying as a share (create c:\apps as a share) or via ftp and see what was created.
  4. The path and environment variable settings only exist for the current terminal. TODO:
    The above commands will only make the .NET SDK commands available for the terminal session in which it was run. 
    You can edit your shell profile to permanently add the commands. There are a number of different shells available for Linux and each has a different profile. For example: 
    Bash Shell: ~/.bash_profile, ~/.bashrc
    Korn Shell: ~/.kshrc or .profile 
    Z Shell: ~/.zshrc or .zprofile 
    Edit the appropriate source file for you shell and add :$HOME/dotnet to the end of the existing PATH statement. If no PATH statement is included, add a new line with export PATH=$PATH:$HOME/dotnet. 
    Also add export DOTNET_ROOT=$HOME/dotnet to the end of the file
    
  5. Lets create a web app:
    • Make a new folder in apps called say web1 and change into it.
    • Run dotnet new webapp
    • Open the file Program.cs … Resolving the Insecurity.
      • Insert the line webBuilder.UseUrls("http://*:5001/"); after the line webBuilder.UseStartup<Startup>();
      • Nb: Reference to this here Thanks Gunnar!
    • Then run dotnet run
    • In the browser on the RPi enter URL http://localhost:5001
      • This will also work remotely
        • Get ipAddress from the command /sbin/igconfig
    • And here we have it (From web browser on Windows desktop):

      .NET Core WebApp

    • Alternatively use curl in the terminal:
      • Enter curl http://localhost:5001
      • You’ill get the web page file contents displayed.😀
      • Enter wget http://localhost:5001
      • Then cat index.html

From the first project creation:
Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Find out what’s new: https://aka.ms/dotnet-whats-new
Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https
Use ‘dotnet –help’ to see available commands or visit: https://aka.ms/dotnet-cli-docs
Write your first app: https://aka.ms/first-net-core-app

*Next: .NET Core on IoT: On Windows Subsystem for Linux


 TopicSubtopic
  Next: > .NET Core on IoT
<  Prev:   .NET Core on IoT
This Category:.NET Core on IoT
  Next: > .NET Core on IoT On Windows Subsystem for Linux 
<  Prev:   .NET Core on IoT