Reconsider Minimal API on .NET Core in 5 minutes on WSL
.NET is trying to fit more with DX (Developer experience). Now it run on Mac, WSL, Linux and bring in more style that us, developer love.
command line — lighter weight — develop incrementally
So I reconsider it shortly and would like to show you some.
Install .NET on WSL
To start you need add .NET repos because it is private, then go with the classic sudo apt install
# Make private repos works with APT
declare repo_version=$(if command -v lsb_release &> /dev/null; then lsb_release -r -s; else grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"'; fi)
wget https://packages.microsoft.com/config/ubuntu/$repo_version/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt update
# Install the SDK
sudo apt install dotnet-sdk-7.0
Source: https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#supported-distributions
If you are confused, you need the SDK version. SDK version has everything to dev including runtime.
Create the project: Minimal API
Now you have the command line to create the project
dotnet new web -o learn-dotnet
Open VS code then install extension and hit Ctrl+F5
then you will get the browser pop to open.
Alternatively our favorite command line interface
Yes we love command line. Now they have one
# Inside project folder
dotnet run
or better with hot reloading
dotnet watch
I notice sometimes there is a reload bug.
To force rebuild you need to hit
Ctrl+R
Then you go to browser to see the hello world.
http://localhost:5173/
Troubleshooting: SDK not found
You can examine your completeness of installation by
dotnet --info
...
# NOT COMPLETE
.NET SDKs installed:
No SDKs were found
The SDK is there but in the wrong location. You can link it to the default location by below ln
command.
for f in /usr/share/dotnet/* ; do; sudo ln -s $f /usr/lib/dotnet ; done