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.
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
The VSCode team is aware of this, so you will find a warning about this scenario
Even so, you can still use VSCode to edit and build C# .Net Core Projects.
And you can run them also
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!
Greetings @ Burlington
- How to Manage File and Folder Permissions in Linux https://www.linux.com/tutorials/how-manage-file-and-folder-permissions-linux/
- Ask Ubuntu Why is it bad to log in as root? https://askubuntu.com/questions/16178/why-is-it-bad-to-log-in-as-root
- GitHub –user-data-dir incorrect help https://github.com/Microsoft/vscode/issues/41429
- El Bruno, How to install .Net Core in a Raspberry Pi 4 and test with HelloWorld https://elbruno.com/2019/08/27/raspberrypi-how-to-install-dotnetcore-in-a-raspberrypi4-and-test-with-helloworld-of-course/
- Installing Visual Studio Code in a Raspberry Pi https://elbruno.com/2019/08/20/vscode-installing-visual-studio-code-in-a-raspberrypi-a-couple-of-lessons-learned-code/