.NET Core on IoT: On Windows Subsystem for Linux
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.
- Setup WSL and Debian
- MS Dox Reference
- Setup WSl on Windows 10
- PowerShell command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
OR - Control Panel - Programs and Features - Turn Windows Features on and off - [ ] Windows Subsystem for Linux Check it
- Reboot when done.
- PowerShell command:
- Install Debian
- Download and install from the Microsoft Store:
- [Launch] and create login account (I used Pi!) when prompted.
- Try these commands:
echo $(pwd)
/home/pi
cat /etc/debian_version
10.0
- Add some functionality
N.b. Responses where shown (if short) are indented.netstat bash: netstat: command not found sudo apt-get update sudo apt-get install -y net-tools netstat ... Works now. sudo apt-get install curl curl curl: try 'curl --help' or 'curl --manual' for more information ... OK sudo apt-get install wget wget Usage: wget [OPTION]... [URL]... ... OK
- 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.
- Before installing .NET, youβll need to:
- Installing .NET Core
- MS Dox Reference: Debian 10 Package Manager - Install .NET Core
- Install the .NET Core SDK
sudo apt-get update sudo apt-get install apt-transport-https
then
sudo apt-get update sudo apt-get install dotnet-sdk-3.1
- Check
dotnet --version 3.1.100
- 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!
- 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 linewebBuilder.UseStartup<Startup>();
- Nb: Reference to this here Thanks Gunnar!
- Insert the line
- Then run
dotnet run
- In the desktop browser (i.e. in Windows) enter URL
http://localhost:5001
And here we have it:
- 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
- Enter ```curl http://localhost:5001
Next: Time for some Azure IoT Hub apps in .NET Core. (Coming)
Topic | Subtopic | |
This Category Links | ||
Category: | IoT Index: | IoT |
Next: > | .NET Core on IoT | Fast tracking IoT Hub Creation with PS |
< Prev: | .NET Core on IoT | Getting started on Raspbian |