6

I am using VS Code and Unity.

Under the output tab (omnisharp log) I get this error

Starting OmniSharp server at 5/27/2022, 3:16:43 AM
    Target: /Users/<my.name>/unity/Test Project 3/Test Project 3.sln

[ERROR] Error: Command failed: dotnet --version
/bin/sh: dotnet: command not found

However, when I go the console, I can run dotnet --version just fine

dotnet --version
6.0.202

I now get the unity console telling me that the print command is invalid, but that error isn't highlighted in vs code.

Update: it seems to work if I open VS Code from the terminal. Doing research, it has something to do with the path. Still unsure why it doesn't normally work.

Sean AH
  • 486
  • 4
  • 8
  • 1
    Do you run your application and `dotnet --version` command(when it gives output) on the same machine? Maybe you run your application in the Docker container? – OlegI May 27 '22 at 09:31
  • Yes everything is on the same machine – Sean AH May 27 '22 at 09:32
  • I will ask if you are using an M1 Mac. Unless you have all binaries in ARM64, such errors are expected. – Lex Li May 27 '22 at 16:00
  • MacOS Montgomery 12.1 (21C52) - Macbook Air. I'm glad I found a workaround, but what if I hadn't? I just have to live with errors? – Sean AH May 27 '22 at 16:41
  • I am getting the exact same error. I am using macOS Catalina 10.15.7. It used to work fine just a few weeks ago. – Ben Jun 04 '22 at 12:15
  • 1
    @SeanAH Try adding to your user settings file the two lines described here: https://stackoverflow.com/a/72385697/795016 Then make sure to fully close and reopen VSCode. his solved it for me! – Ben Jun 04 '22 at 12:22
  • This should be an answer. I actually did this a while ago to solve a related problem. I didn't check if it solved my original problem at the time, but I now see that I'm not getting it any more. – Sean AH Jun 04 '22 at 15:19

2 Answers2

3

In your terminal enter: where dotnet

Set this directory for omnisharp.dotnetPath in your VSCode preferences.

Drazen Bjelovuk
  • 5,201
  • 5
  • 37
  • 64
  • 2
    This worked for me. It suddenly stopped working today though. Not sure what I changed before this. Never had to update this before. Thanks for the tip, it helped! – radj Aug 03 '22 at 12:54
0

.Net SDKs are available at this path in Program Files: C:\Program Files\dotnet\sdk
Do you have this .net SDK path set in your 'Environment Variables' -> 'System variables' -> 'Path'? If not, try that.

CSharp
  • 1,573
  • 2
  • 14
  • 25