#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