Building VS project in WSL in GitHub actions

I have a PowerShell script that builds the VS project in WSL in my local machine. But, when I push the same script into Github actions, I get an error. It is not the issue with visual studio because it is building without any error in WSL. It’s not compiling and creating the object files. Can anyone please help me with this issue? The sample of error is as follows:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Application Type\Linux\1.0\Linux.WSL.targets(250,5): error MSB4018: liblinux.Local.Shell.WindowsSubsystemShellException: Could not open windows subsystem shell —> liblinux.Local.Shell.WindowsSubsystemShellException: Failed to start WSL process —> liblinux.Local.Shell.WindowsSubsystemShellException: Echo command failing
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Application Type\Linux\1.0\Linux.WSL.targets(250,5): error MSB4018: at liblinux.Local.Shell.WindowsSubsystemShell.VerifyEcho(TimeSpan timeout)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Application Type\Linux\1.0\Linux.WSL.targets(250,5): error MSB4018: at liblinux.Local.Shell.WindowsSubsystemShell.StartWSLProcess(TimeSpan timeout)

You probably need to run this task on a CI server that has a Windows OS machine with WSL installed too.

From the error reports, it mentions that the machine is unable to start the WSL process, so you’ll need to set that up correctly first.

You could try using Travis CI, which also offers Windows for building, and gives you the chance to install all required apps before executing the job.

I have been using GitHub Actions windows Self-Hosted Runner for the CI server. I have wsl on my VM in windows. The program is not compiling using wsl from Github actions. When I try to run the same project in my local machine instead of Github actions, it works. So, I am trying to understand what the problem is.

I don’t use GitHub Actions, but my guess is that like other CI services it comes with some default settings and apps for each OS Virtual Machine, and it looks like it doesn’t have WSL by default. So you’ll have to ensure that your Action first installs and enables all required tools and services before running the job — i.e. since it’s working on your local machine, you only need to make sure that all dependencies are available on the GH VM.