omnisharp-roslyn: MSBuild can not be found on Arch Linux

Since yesterday I keep getting this error when omnisharp starts up in vscode (omnisharp is set to latest version):

[warn]: OmniSharp.MSBuild.Discovery.Providers.MonoInstanceProvider
        It looks like you have Mono 5.2.0 or greater installed but MSBuild could not be found.
Try installing MSBuild into Mono (e.g. 'sudo apt-get install msbuild') to enable better MSBuild support.

This used to work without issues before. I noticed that msbuild version was increased in a recent commit. Maybe that causes omnisharp to no longer find my msbuild on linux?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 43 (6 by maintainers)

Most upvoted comments

Since you are on Arch, it’s no surprise that MSBuild cannot find your .NET Core SDK: not only it’s installed in non-standard location, but also /usr/bin/dotnet is not a symlink and DOTNET_ROOT is not globally exported. Try the following (multiple at the same time if necessary):

  • Replace /usr/bin/dotnet with a symlink to /opt/dotnet/dotnet
  • Create a file in /etc/profile.d, e.g. dotnet.sh, with the following content: export DOTNET_ROOT=/opt/dotnet (you might need to adapt this for some login shells, and make sure you relog afterwards)
  • Set UseLegacySdkResolver to true in your omnisharp.json

You could instead try exporting MSBuildSdksPath, but it’s very prone to breakage and prevents you from using multiple SDK versions.

See here for some details on what I found about .NET Core packages in Arch.

@notaduck what steps you did? I was tried DOTNET_ROOT but no luck.

I removed /usr/bin/dotnet and replaced it with /opt/dotnet/dotnet

sudo ln -s /opt/dotnet/dotnet /usr/bin/dotnet

Nothing else 😃

Install msbuild-16-bin from AUR and latest mono from official repository as suggested here works for me.

I can confirm that @Saancreed’s solution also worked for me without installing mono and msbuild-bin-16.

@masaeedu I vaguely recall seeing some piece of code that attempts to find first dotnet in $PATH and resolve it with realpath, but now that I tried to locate it again, I actually couldn’t. So I might have been mistaken here, or something was changed in 3.1 and it’s just no longer there. Anyway, source is available here, just in case you want to take a look.

Install msbuild-16-bin from AUR and latest mono from official repository as suggested here works for me.

This also helped me.

Install msbuild-16-bin from AUR and latest mono from official repository as suggested here works for me.

This worked for me as well.

  • I’m pretty sure that /usr/bin/dotnet is a shell script that execs /opt/dotnet/dotnet
  • As for why it used to work, well, you said it yourself: a few days ago OmniSharp updated its MSBuild to 16.3, which might have changed SDK resolution logic. So, you could also try reverting to an older version of omnisharp-roslyn and if it works without any other changes, then bisect can get us more info.

You could also try getting msbuild and msbuild-sdkresolver from AUR, as your error log suggests that OmniSharp attempts to load extensions from legacy xbuild instead.

That said. what I can assure you is that it can work, but in my case it’s probably because I build my own mono, msbuild and omnisharp packages from source: https://pastebin.com/PZiJ8bBQ (although it’s not very relevant here).