Search code examples
c#.netvisual-studio-code.net-corewindows-10

Dotnet: Works in VSCode's OWN TERMINAL, but OMNISHARP: 'dotnet.exe' is not recognized


How is this possible?

  • I installed .net sdk 6.0.405: dotnet-sdk-6.0.405-win-x64.exe
  • I can in windows terminal and power shell run: dotnet --version: 6.0.405 ✅
  • I CAN ALSO IN VSCODE IN ITS BUILTIN TERMINAL, run: dotnet --version: 6.0.405 ✅✅
  • But in the OUTPUT tab, choosing OmniSharp Log from the dropdown, it says:

[ERROR] A .NET 6 SDK for x86_64 was not found. Please install the latest x86_64 SDK from ...

I switched vscode explorer settings to use external terminal.

And this terminal setting to command prompt:

Terminal › Integrated › Default Profile: Windows The default profile used on Windows. This setting will currently be ignored if either terminal.integrated.shell.windows or terminal.integrated.shellArgs.windows are set.

I have dotnet in the PATH (and it works in terminals and in vscode's terminal)

I restarted vscode, AND REINSTALLED the dotnettools "C# for Visual Studio Code (powered by OmniSharp)" extension. I went to the online store and from the right column under Resources I downloaded the [email protected] to make sure I get the right one. And restarted vscode.

I tried this setting:

Omnisharp: Dotnet Path Specified the path to a dotnet installation to use when "useModernNet" is set to true, instead of the default system one. This only influences the dotnet installation to use for hosting Omnisharp itself. Example: "/home/username/mycustomdotnetdirectory".

C:/Program Files/dotnet/sdk/6.0.405

And this setting:

Omnisharp: Sdk Path Specifies the path to a .NET SDK installation to use for project loading instead of the highest version installed. Applies when "useModernNet" is set to true. Example: /home/username/dotnet/sdks/6.0.300.

C:/Program Files/dotnet/sdk/6.0.405

And restarted vscode. And now it says:

[ERROR] Error: Command failed: dotnet.exe --version 'dotnet.exe' is not recognized as an internal or external command, operable program or batch file.

What? W H A T? lol

What could be wrong? Why isn't it saying where it expected to find it and what to do to locate it? Is there a setting to specify the dotnet.exe path to this C# extension? Does it need always-on internet or something? Does it have DRM? Does it need Edge installed? Wtf?🙂

🙃😭 I just need intellisense; and I've wasted 2h, on only microsoft-owned products. #Microsoft 0/5 stars


Solution

  • Still don't know why it happens, but here's how to solve it:

    The problem was from this: I like to keep all my visual studio code extensions as .vsix files locally in folders so I can remember and get them easily & offline. Sensible enough choice, and I had the correct [email protected] for my platform.

    But in VSCode, when I install this particular extension via VSIX, even though it succeeds, it can't find .net. If you instead install the extension "normally", ie via vscode's own download, it seems vscode does some extra configuration steps while installing, and probably sets the .net paths correctly or something. Because now it works.

    So TL;DR: don't install ms-dotnettools.csharp via vsix, it seems bugged. 😶


    Would love to see an answer explaining what's wrong / how to actually do via vsix; but I don't have any more time to debug this rn.