#RaspberryPi – How to solve #dotnet core not recognized after reboot

Buy Me A Coffee

Hi!

So, after writing my posts on how to install dotnet core 3.1 on a Raspberry Pi 4, I found that after I reboot my device, the dotnet command stop working. When I run dotnet from bash I get the following message

~bash: dotnet: command not found

dotnet command not found

The problem, is that the export steps of the installation process were lost after the reboot. And, as reminder of what is the export command.

Linux export command is use to set export attribute for shell variables on Linux system. The Linux export command is one of bash shell built in command.

In order to fix this, we can add the commands into our [~/.bashrc] file. First we need to edit our file with the command

sudo nano ~/.bashrc

And add the lines

export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$HOME/dotnet
export PATH="$PATH:/home/pi/.dotnet/tools"
raspberry pi 4 edit bashrc to add dotnet core wrapper

Now we need to reload the [~/.bashrc] file with the command

source ~/.bashrc
dotnet command working after reload bash file

And that’s it ! if the command is not recognized, just reload the bashrc file.

Happy coding!

Greetings @ Burlington

El Bruno

My posts on Raspberry Pi

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware

#VSCode – Build and Run C# #DotNetCore projects in #RaspberryPi

Hi!

Time to move on with some lessons learned using Visual Studio Code in the Raspberry Pi 4.

One of the first issues you may find working with VSCode in the device is related to file write permissions when you are saving a file.

I raspberry pi 4 visual studio code failed to save file

So, it was a good opportunity for me to learn about files and folder permissions in Linux. I found a great starting article “How to Manage File and Folder Permissions in Linux” (see references), and it allowed me to fix this issue.

My next error was triggered when I try to build my project. Again, it was a permission related error.

/home/pi/dotnet/sdk/2.2.401/Microsoft.Common.CurrentVersion.targets(4195,5):
error MSB3021: Unable to copy file "obj/Debug/netcoreapp2.2/dotnethelloworld.dll"
to "bin/Debug/netcoreapp2.2/dotnethelloworld.dll". Access to the path
is denied. [/home/pi/dotnethelloworld/dotnethelloworld.csproj]

However, this time the fix was not related to file and folder permissions.

One of the solutions I found, was to run VSCode with admin privileges. This is probably one of the worst ideas ever, and you can find tons of articles explaining why this is bad (see references).

Anyways, I decided to give it a try. Of course, it worked. Let me share how.

I run VSCode with the following command, which runs the app in root mode.

sudo
code-oss --user-data-dir=/home/pi/dotnethelloworld
raspberry pi 4 visual studio code run as root

The VSCode team is aware of this, so you will find a warning about this scenario

raspberry pi 4 visual studio code run as root warning

Even so, you can still use VSCode to edit and build C# .Net Core Projects.

raspberry pi 4 visual studio code build code

And you can run them also

raspberry pi 4 visual studio code build and run edited code

So far, so good. Or maybe not, broken a lot of good practices. I’ll see this as an amazing chance to learn and test new stuff!

Happy coding.

Greetings @ Burlington

El Bruno

References

My posts on Raspberry Pi

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware