OmniSharp/omnisharp-roslyn

Omnisharp tries to use MSBuild < 16.3 from Visual Studio 2019 in .NET Core 3.x projects

Closed this issue ยท 19 comments

Issue Description

Starting a console project from scratch using the command line tools results in code that Intelisense thinks is wrong. There red lines everywhere, even though the code compiles and runs with no problem.

image

Steps to Reproduce

  1. Install dotnet core 3.1
  2. Install VSCode from scratch
  3. Install C# extension
  4. In the command line, enter an empty folder named 'teste' and type dotnet new console

Expected Behavior

No errors should be present

Actual Behavior

Intelisense show errors everywhere

Logs

OmniSharp log

Starting OmniSharp server at 29/01/2020 10:36:05
Target: d:\Documents\teste

OmniSharp server started.
Path: c:\Users\Andre.vscode\extensions\ms-vscode.csharp-1.21.9.omnisharp\1.34.9\OmniSharp.exe
PID: 7248

Starting OmniSharp on Windows 6.2.9200.0 (x64)
info: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 2 MSBuild instance(s)
1: Visual Studio Community 2019 16.2.29306.81 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin"
2: StandAlone 16.3 - "c:\Users\Andre.vscode\extensions\ms-vscode.csharp-1.21.9.omnisharp\1.34.9.msbuild\Current\Bin"
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: Visual Studio Community 2019 16.2.29306.81 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin"
info: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in 'd:\Documents\teste'.
info: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
info: OmniSharp.MSBuild.ProjectSystem
No solution files found in 'd:\Documents\teste'
info: OmniSharp.MSBuild.ProjectManager
Queue project update for 'd:\Documents\teste\teste.csproj'
info: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in 'd:\Documents\teste'.
info: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
info: OmniSharp.MSBuild.ProjectManager
Loading project: d:\Documents\teste\teste.csproj
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.EditorConfigWorkspaceOptionsProvider, Order: 200
info: OmniSharp.WorkspaceInitializer
Configuration finished.
info: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location 'd:\Documents\teste' on host 4164.
info: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file 'd:\Documents\teste\teste.csproj'.
info: OmniSharp.MSBuild.ProjectManager
Adding project 'd:\Documents\teste\teste.csproj'
info: OmniSharp.MSBuild.ProjectManager
Update project: teste
[warn]: OmniSharp.MSBuild.PackageDependencyChecker
teste: Did not find 'Microsoft.NETCore.App' in lock file.
info: OmniSharp.MSBuild.ProjectManager
Queue project update for 'd:\Documents\teste\teste.csproj'
info: OmniSharp.MSBuild.ProjectManager
Loading project: d:\Documents\teste\teste.csproj
info: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file 'd:\Documents\teste\teste.csproj'.
info: OmniSharp.MSBuild.ProjectManager
Update project: teste
[warn]: OmniSharp.MSBuild.PackageDependencyChecker
teste: Did not find 'Microsoft.NETCore.App' in lock file.
info: OmniSharp.MSBuild.ProjectManager
Queue project update for 'd:\Documents\teste\teste.csproj'
info: OmniSharp.MSBuild.ProjectManager
Loading project: d:\Documents\teste\teste.csproj
info: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file 'd:\Documents\teste\teste.csproj'.
info: OmniSharp.MSBuild.ProjectManager
Update project: teste
[warn]: OmniSharp.MSBuild.PackageDependencyChecker
teste: Did not find 'Microsoft.NETCore.App' in lock file.
info: OmniSharp.MSBuild.ProjectManager
Queue project update for 'd:\Documents\teste\teste.csproj'
info: OmniSharp.MSBuild.ProjectManager
Loading project: d:\Documents\teste\teste.csproj
info: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file 'd:\Documents\teste\teste.csproj'.
info: OmniSharp.MSBuild.ProjectManager
Update project: teste
[warn]: OmniSharp.MSBuild.PackageDependencyChecker
teste: Did not find 'Microsoft.NETCore.App' in lock file.
info: OmniSharp.MSBuild.ProjectManager
Queue project update for 'd:\Documents\teste\teste.csproj'
info: OmniSharp.MSBuild.ProjectManager
Loading project: d:\Documents\teste\teste.csproj
info: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file 'd:\Documents\teste\teste.csproj'.
info: OmniSharp.MSBuild.ProjectManager
Update project: teste
[warn]: OmniSharp.MSBuild.PackageDependencyChecker
teste: Did not find 'Microsoft.NETCore.App' in lock file.

C# log

Post the output from Output-->C# here

Environment information

VSCode version: 1.41.1
C# Extension: 1.21.9

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.101 Commit: b377529961

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.101\

Host (useful for support):
Version: 3.1.1
Commit: a1388f194c

.NET Core SDKs installed:
2.1.801 [C:\Program Files\dotnet\sdk]
2.1.802 [C:\Program Files\dotnet\sdk]
3.1.101 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
csharp ms-vscode 1.21.9

forgot to add C# output. Here it goes

Installing C# dependencies...
Platform: win32, x86_64

Downloading package 'OmniSharp for Windows (.NET 4.6 / x64)' (32146 KB).................... Done!
Validating download...
Integrity Check succeeded.
Installing package 'OmniSharp for Windows (.NET 4.6 / x64)'

Downloading package '.NET Core Debugger (Windows / x64)' (47489 KB).................... Done!
Validating download...
Integrity Check succeeded.
Installing package '.NET Core Debugger (Windows / x64)'

Downloading package 'Razor Language Server (Windows / x64)' (50022 KB).................... Done!
Installing package 'Razor Language Server (Windows / x64)'

Finished

Hi @andremarcondesteixeira,
It's because you have 1: Visual Studio Community 2019 16.2.29306.81 installed, which doesn't support .NET Core 3.1
Please update it to latest version or uninstall completely.

I don't get it. Shouldn't VS Code be separeted from Visual Studio?

I think it's a bug, because Omnisharp is trying to use the environment from another IDE. The extension is a VS Code extension, but is affected by Visual Studio not supporting dotnet core

Hi @andremarcondesteixeira ,

In order to support both Full Framework and .NET Core projects, we rely on the Full Framework MSBuild. We package a minimal MSBuild with OmniSharp (it is prohibitive to include a full MSBuild because of the size), but defer to a full installation when one is found on your machine, since it will have all build tasks and target files included. In this case it is just an unfortunate circumstance that the Full Framework MSBuild you have installed does not support the newer .NET Core SDK that you are using.

Is there any way I can help with this?

@andremarcondesteixeira, The best solution is to either update your Visual Studio (lots of improvements since VS16.2) or you could install the latest Visual Studio Build Tools to get a version of MSBuild that supports .NET Core 3.1.

Shouldn't there be a fallback to the VS Code version of MSBuild upon error? I have VS installed and user-mode VS Code installed, and do not have local admin rights. So I cannot update Visual Studio.

@symbiogenesis You can force the use of the minimal MSBuild by creating a omnisharp.json file in your C:\Users{Your username}.omnisharp folder

omnisharp.json (update version numbers as appropriate)

{
    "MSBuild": {
        "msbuildoverride": {
            "MSBuildPath": "C:\\Users\\{your username}\\.vscode\\extensions\\ms-vscode.csharp-1.21.10\\.omnisharp\\1.34.10\\.msbuild\\Current\\Bin",
            "Name": "OmniSharp MSBuild",
            "PropertyOverrides": {
                "MSBuildExtensionsPath": "C:\\Users\\{your username}\\.vscode\\extensions\\ms-vscode.csharp-1.21.10\\.omnisharp\\1.34.10\\.msbuild"
            }
        }
    }
}

Would be great to have a boolean setting for this, so that I won't need to update the MSBuildPath on every upgrade.

I think it's a bug, because Omnisharp is trying to use the environment from another IDE. The extension is a VS Code extension, but is affected by Visual Studio not supporting dotnet core

We periodically raise the minimum version of VS that can be discovered and used. For example VS 2017 is never used anymore, even though it used to be.
The lowest one OmniSharp picks is VS 2019 16.0 but for .NET Core 3.x 16.3 is needed. It's a chicken and egg problem since OmniSharp picks MSBuild before knowing the framework (it needs MSBuild to recognize the framework). This was caused by the fact that .NET SDK team raised the minimum MSBuild version from 16.0 to 16.3 between the last RC of .NET Core 3 and the RTM version.

This "issue" will go away on its own once we raise the minimum VS 2019 version to 16.3 which I think we will do soon.
That said, while you are free to consider this being a "bug" I don't think it's a terrible assumption that if you want to do .NET Core 3.x development and VS2019 is on your machine, it would have been update to support .NET Core 3.x in the first place.

But as mentioned, it will resolve itself once we raise the minimum VS 2019 version.

Also, I will move this issue to the server repo as it belongs there.

@JoeRobich @david-driscoll @mholo65 should we just raise the min. VS to 16.3 and be done with this? it should help avoid a bunch of those .NET Core 3.x issues

// VS 2019 should be preferred
if (i.Version.Major >= 16)
score++;
else
score--;

@filipw I'm ok with raising the min version to 16.3... Best would be if we could check what the target framework is and then set min version to 16.3 if project targets .NET Core 3.x. Problem is that we know the target framework after project have been processed by OmniSharp.MSBuild stuff, which needs MSBuild ๐Ÿ˜„ So it's really a chicken-egg situation.

@filipw I'm ok with the change. I think it is reasonable to expect late adopters to at least keep up with the last LTS release and 16.4 was an LTS release for us.

do you have maybe access to some telemetry on how installations of 16.x versions are distributed?
also, at the end of the day, these folks wouldn't be left in a broken state, they'd just move to the bundled msbuild like i.e. those who only have VS2017 installed

@filipw Of users who report telemetry, they are overwhelmingly using VS16.3+

FYI I'm seeing similar issues now that dotnet 5 dropped. Even though I have StandAlone 16.8.0 installed, it must be using an old Visual Studio Community 2019 16.6.30204.135. The omnisharp.json file didn't work for me, and I agree with the prior sentiment that I don't want to keep that file up to date as versions increase.

Trying to load a simple test project for net5.0

Omnisharp log:
Failed to load project file 'testconsoleapp.csproj'.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1177,5): Error: The reference assemblies for .NETFramework,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

It is a chicken and egg situation. OmniSharp doesn't know the version of the framework since it needs MSBuild for that. Unfortunately the lowest compatible version with .NET Core 3.1 is 16.3 and the lowest compatible with .NET 5.0 is 16.8.

For now we select 16.3 as the lowest since most people use .NET Core 3.1 but it will be raised to 16.8 in the future.

The stand alone 16.8 that is bundled with Omnisharp is a minimal instance that doesn't contain desktop references or doesn't support Unity development, therefore we always select the instance from Visual Studio if it's there and it's > 16.3.

My recommendation is to just upgrade VS to latest - VS 16.8 is available since last week, and, in fact, should auto popup the update notification.

If overriding by hand with omnisharp.json doesn't work for for you please open a new issue with repro steps and OmniSharp log - thanks.

Thanks, @filipw. I just upgraded my VS 2019 install. Size of the download was ridiculous, though. Everything is working and I have intellisense in VSCode again.