VS Code C# Extension not working in Remote SSH mode on Red Hat Linux? Here's a workaround
Niels Swimberghe - - .NET
Follow me on Twitter, buy me a coffee
Visual Studio Code has an extension called "Remote - SSH" that allows you to use Visual Studio Code as your editor for SSH enabled machines. For example, this means you can use VS Code on Windows but develop on a Red Hat VM. Say goodbye to getting stuck in vim or being shamed for using nano. 😿
Unfortunately, the C# Extension for VS Code malfunctions when following the official steps to install .NET Core on Red Hat and using the Remote SSH extension. OmniSharp, the underlying cross-platform .NET engine for the C# extension is not able to find the .NET Core installation. When opening a .NET project in remote SSH mode on Red Hat, you will likely see "It was not possible to find any installed .NET Core SDKs".
The workaround is just that, a workaround. I do not recommend doing this in production scenarios, only do this in your development environment.
To work around OmniSharp not finding the .NET Core installation, you can create a symbolic link from the 'dotnet' executable to a path in your $PATH environment variable such as '~/bin/'.
DOTNETLOCATION=$(which dotnet) sudo ln -s $DOTNETLOCATION ~/bin/dotnet
Using the `which dotnet`
command, you fetch the location of the executable 'dotnet'-file.
This path is stored in the `DOTNETLOCATION` variable which is then used to create a soft symbolic link to '~/bin/dotnet'. After running these 2 commands, quite VS Code and open the same .NET project on Red Hat using the SSH Remote extension. Now OmniSharp will find your .NET installation and the C# extension will behave as expected.
Hopefully this issue gets resolved in the future and the C# extension will behave as expected without the workaround. The issue has been reported over at the 'omnisharp-vscode' GitHub repo, please review the issue for any updates.