1

Due to the third party system we work against, I have to use .Net 2.1, which has worked fine until recently. I develop on Fedora with latest updates and VSCode. This seems similar to Could not locate MSBuild instance to register with OmniSharp but I get the warning about msbuild version number, where that question did not.

Now when opening my VSCode project I get this Omnisharp output:

Starting OmniSharp server at 28/03/2022, 09:48:44
    Target: /home/neek/workspace/LinnworksNetSDKProjects/PremierZenCartMacro/Linnworks/Examples/OrdersDashboard/dotnet/LinnworksNet-NativeModule-OrdersDashboard.sln

OmniSharp server started with Mono 6.12.0.
    Path: /home/neek/.vscode/extensions/ms-dotnettools.csharp-1.24.1/.omnisharp/1.38.3-beta.31/omnisharp/OmniSharp.exe
    PID: 8252

[dbug]: OmniSharp.CompositionHostBuilder
        Loaded OmniSharp.Cake, Version=1.38.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
[dbug]: OmniSharp.CompositionHostBuilder
        Loaded OmniSharp.DotNetTest, Version=1.38.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
[dbug]: OmniSharp.CompositionHostBuilder
        Loaded OmniSharp.Host, Version=1.38.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
[dbug]: OmniSharp.CompositionHostBuilder
        Loaded OmniSharp.MSBuild, Version=1.38.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
[dbug]: OmniSharp.CompositionHostBuilder
        Loaded OmniSharp.Roslyn, Version=1.38.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
[dbug]: OmniSharp.CompositionHostBuilder
        Loaded OmniSharp.Roslyn.CSharp, Version=1.38.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
[dbug]: OmniSharp.CompositionHostBuilder
        Loaded OmniSharp.Script, Version=1.38.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
[dbug]: OmniSharp.CompositionHostBuilder
        Loaded OmniSharp.Shared, Version=1.38.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on fedora 35.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to /home/neek/dotnet/dotnet
[dbug]: OmniSharp.CompositionHostBuilder
        .NET SDK requires MSBuild instances version 16.0.0 or higher
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 0 MSBuild instance(s)
Could not locate MSBuild instance to register with OmniSharp.
[ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute).

It claims .NET SDK requires MSBuild instances version 16.0.0 or higher however I believe this is installed:

$ dotnet msbuild -h
Microsoft (R) Build Engine version 16.2.37902+b5aaefc9f for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

dotnet was installed manually under my home directory and added to the $PATH as per installation instructions:

$ which dotnet
~/dotnet/dotnet

Could be related to https://github.com/OmniSharp/omnisharp-vscode/issues/5120 where they talk about omnisharp.useModernNet. In my Settings UI in VSCode, I can see 'Use Modern Net' is false, which I think is correct as I don't want to use a 'modern' .Net, I have to use the 2.1 SDK.

If I set useModernNet to true, then omnisharp appears to download .Net 6 packages:

Installing C# dependencies...
Platform: linux, x86_64, name=fedora, version=35

Downloading package 'OmniSharp for Linux (.NET 6 / x64)' (39471 KB).................... Done!
Validating download...
Integrity Check succeeded.
Installing package 'OmniSharp for Linux (.NET 6 / x64)'

Finished

Getting latest OmniSharp version information
Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done!

I can then run the 'build' command (my tasks.json specifies the command as /home/neek/dotnet/dotnet) and it appears to compile normally.

It is wrong to be telling Omnisharp to use .Net 6 when my code actually wants to compile using the 2.1 SDK installed? Should I be turning off useModernNet, and if so, how to I fix the Omnisharp error about not finding msbuild?

Neek
  • 7,181
  • 3
  • 37
  • 47

1 Answers1

1

Remove the msbuild error by setting the following:

"omnisharp.path": ""

Use the newer .NET 6.0 version of OmniSharp (which has nothing to do with your code and target framework) by setting the following:

"omnisharp.useModernNet": true
Mani Gandham
  • 7,688
  • 1
  • 51
  • 60
  • Thank you @Mani .. I got it working after reinstalling the SDK, I can hit f5 to debug the project. But, when I 'reload Omnisharp' it fails after a couple of lines saying "[ERROR] Error: Found dotnet version 2.1.818. Minimum required version is 6.0.100.". I tried settings.json `{ "omnisharp": { "path": "" } }` (I think is what you mean?) with no effect. Also tried `dotnetPath` pointing to my `dotnet/sdk` folder. It does seem to find my dotnet 2.1 SDK, great, but omnisharp thinks the sln asks for 6.0.100. Every csproj has `TargetFramework` `netstandard2.0` (or `2.1`). Weird. – Neek May 19 '22 at 02:57
  • 1) You can use periods in the key names so you can copy what I wrote exactly. 2) Did you set the `useModernNet` flag to `true`? Omnisharp is a C# program and needs .NET 6 SDK installed to run so do you have that installed? https://github.com/OmniSharp/omnisharp-vscode#using-net-6-builds-of-omnisharp – Mani Gandham May 19 '22 at 10:46