Digressing a little: A look at getting .NET Core going on Windows Subsystem for Linux using Debian. Debian because that is what Raspbian is. The Console app and Blazor web app as well. Includes first time set up of WSL-Debian.

Whilst in my former occupations I used Linux a bit, that was sometime ago. I have touched on it occasionally since then but I needed a desktop platform to check out some functionality as Raspbian on the RPi is Debian, a Linux flavour. So as an exercise I elected to get .NET Core running on Windows Subsystem for Linux with Debian mounted as the OS.

If you have an existing Debian installation, whether in wsl or otherwise skip to 3.

  1. Setup WSL and Debian
    • MS Dox Reference
    • Setup WSl on Windows 10
      • PowerShell command: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
      • Control Panel - Programs and Features - Turn Windows Features on and off - [ ] Windows Subsystem for Linux Check it wsl
      • Reboot when done.
    • Install Debian
      • Download and install from the Microsoft Store:
      • [Launch] and create login account (I used Pi!) when prompted. Debianl
      • Try these commands:
        • echo $(pwd)
        • cat /etc/debian_version
  2. Add some functionality
    N.b. Responses where shown (if short) are indented.
          bash: netstat: command not found
     sudo apt-get update
     sudo apt-get install -y net-tools
          ... Works now.
     sudo apt-get install curl
          curl: try 'curl --help' or 'curl --manual' for more information   ... OK
     sudo apt-get install wget
          Usage: wget [OPTION]... [URL]...   ... OK
  3. Enabling .NET Core installation
    • MS Dox Reference: Debian 10 Package Manager - Install .NET Core
    • Register Microsoft key and feed
      • Before installing .NET, you’ll need to:
        • Register the Microsoft key.
        • Register the product repository.
        • Install required dependencies
      • Need another installation first: (Nb: It might already be there)
          sudo apt-get update
          sudo apt-get install gpg
      • The commands to implement this section:
          wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
          sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
          wget -q https://packages.microsoft.com/config/debian/10/prod.list
          sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
          sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
          sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
      • Nb: Had to run the first command (wget) on its own. Could copy and paste the rest in one hit.
  4. Installing .NET Core
  5. Console App
    • 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 (Again)! πŸ†πŸ†πŸ†πŸ†πŸ†
     dotnet run
          Hello World!
  6. Web App (MVC)
    • Make a new folder in apps called say web1 and change into it.
    • Run dotnet new blazorserver
    • Open the file Program.cs
      • 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 desktop browser (i.e. in Windows) enter URL http://localhost:5001
      And here we have it:

      Dotnet Blazor
    • Alternatively use curl or wget in the terminal (Need another Debian window or can do from Windows if installed)):
      • Enter ```curl http://localhost:5001
        • You’ll get the web page file contents displayed.πŸ˜€
      • Enter ```wget http://localhost:5001
      • Then cat index.html

Next: Time for some Azure IoT Hub apps in .NET Core. (Coming)

 This Category Links 
Category:IoT Index:IoT
  Next: > .NET Core on IoT
<  Prev:   .NET Core on IoT