OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.77k stars 421 forks source link

Server fails to start with "OmniSharp requires the .NET 6 SDK or higher be installed." on .NET 6, 7 #2423

Open dkaszews opened 2 years ago

dkaszews commented 2 years ago

Trying to get vim-OmniSharp to work, but the server fails to start, complaining about not finding SDK, despite using the exact one from link in next message. Also an issue with .NET7, both using DOTNET_ROOT or installing in /usr/share/dotnet, despite using both to successfully compile projects. Reproduces on all versions from latest v1.39.1 to v1.38.0 which is oldest supporting .NET6.

OS is Ubuntu 22.04 LTS aarch64 on Raspberry Pi 4 Model B Rev 1.2

Previously opened in vim-OmniSharp, moved here because also fails when run outside vim.

> /home/dkaszews/Downloads/omnisharp-linux-arm64-net6.0/OmniSharp                         
{"Event":"log","Body":{"LogLevel":"INFORMATION","Name":"OmniSharp.Stdio.Host","Message":"Starting OmniSharp on Unknown 0.0 (Unknown)"},"Seq":1,"Type":"event"}
{"Event":"log","Body":{"LogLevel":"INFORMATION","Name":"OmniSharp.Services.DotNetCliService","Message":"Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK"},"Seq":2,"Type":"event"}
{"Event":"log","Body":{"LogLevel":"INFORMATION","Name":"OmniSharp.Services.DotNetCliService","Message":"DotNetPath set to /home/dkaszews/Downloads/dotnet-sdk-6.0.302-linux-arm64/dotnet"},"Seq":3,"Type":"event"}
{"Event":"log","Body":{"LogLevel":"ERROR","Name":"OmniSharp.MSBuild.Discovery.Providers.SdkInstanceProvider","Message":"OmniSharp requires the .NET 6 SDK or higher be installed. Please visit https://dotnet.microsoft.com/download/dotnet/6.0 to download the .NET SDK."},"Seq":4,"Type":"event"}
{"Event":"log","Body":{"LogLevel":"INFORMATION","Name":"OmniSharp.MSBuild.Discovery.MSBuildLocator","Message":"Located 0 MSBuild instance(s)"},"Seq":5,"Type":"event"}
Could not locate MSBuild instance to register with OmniSharp.
dkaszews@Cuddles-Berry:~/code/PowerShell [dkaszews-update-help-implicit-culture +4 ~0 -0 !]

> & "$env:DOTNET_ROOT/dotnet" --info                                                      

global.json file:
  /home/dkaszews/code/PowerShell/global.json

Host:
  Version:      6.0.7
  Architecture: arm64
  Commit:       0ec02c8c96

.NET SDKs installed:
  6.0.302 [/home/dkaszews/Downloads/dotnet-sdk-6.0.302-linux-arm64/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.7 [/home/dkaszews/Downloads/dotnet-sdk-6.0.302-linux-arm64/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.7 [/home/dkaszews/Downloads/dotnet-sdk-6.0.302-linux-arm64/shared/Microsoft.NETCore.App]

Download .NET:
  https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs:
  https://aka.ms/dotnet/runtimes-sdk-info
dkaszews commented 2 years ago

I compiled from source, set $DOTNET_ROOT to the .dotnet in repo, works. Try with OmniSharp downloaded from releases, works. I moved it couple times to another directory and back (always updating $DOTNET_ROOT), never worked outside repo, now doesn't work even in repo. So I guess SdkInstanceProvider has something weird going on with it?

filipw commented 2 years ago

The SDK provider requires dotnet command to be available on your path, it literally runs the process and then checks for the output. Do you have it there?

dkaszews commented 2 years ago

I managed to solve it by setting $DOTNET_ROOT to .NET6 and adding it to $PATH. If I don't add to $PATH, then I get the error as above. If I don't add to $DOTNET_ROOT, then I get an error about missing libhostfxr.so.

Also, I got same error about missing SDK if I used .NET7, it only got resolved by copying the SDK folder from .NET6. Maybe the SdkInstanceProvider does not like the -preview suffix?

  6.0.302 [/home/dkaszews/.dotnet/sdk]
  7.0.100-preview.6.22352.1 [/home/dkaszews/.dotnet/sdk]

Also, why does SdkInstanceProvider does not use $DOTNET_ROOT? It is confusing that one part of OmniSharp tells me that I need to set it, then another silently failes because it cannot find dotnet. If anything, it should provide better error message depeding on whether it cannot find the SDK it likes, or it cannot find dotnet at all.

filipw commented 2 years ago

By default prereleases are not included, they can be included by setting the following option in omnisharp.json https://github.com/OmniSharp/omnisharp-roslyn/blob/04a561ca69584ab0bad1fd3fa75a14006e9afd7d/omnisharp.json#L13-L15

The SdkInstanceProvider yields the search to Microsoft.Build.Locator which is the one that runs and discovers dotnet from the PATH. We can only improve our error message to make it more obvious.

dkaszews commented 2 years ago

Yeah, would be good to distinguish the following cases:

Adding a verbose log which lists all SDKs, then comments which are ignored and why should be good.

If you can point me to the right file, I'll take a look what I can do.