vscode-csharp: C# Extension fails only for netcoreapp3.0 GA

Issue Description

C# Extensions complains “The type or namespace name ‘System’ could not be found …” (likewise System.String, System.Object, System.Void, etc.)

This happens only when Target Framework = netcoreapp3.0. No problems for netcoreapp2.0, netcoreapp2.1, nor netcoreapp2.2. Code builds and runs fine at command prompt.

Steps to Reproduce

  1. Installed software
  • VS Code latest (1.38.1)
  • C# Extensions latest (1.21.3)
  • . . . with OmniSharp latest (1.34.3)
  • .NET Core 3.0 SDK (3.0.100)
  • Restart workstation after installs (just in case)
  1. Actions in Command Prompt
  • Create folder = OmniDemo
  • Create new console app in that folder: dotnet new console
  • dotnet build => builds successfully
  • dotnet run => runs successfully
  • Inspect .csproj file => App uses TargetFramework = netcoreapp3.0.
  1. Open VS Code in this folder
  • Warning = No assets … => Accept to add assets
  • Warning = Unresolved dependencies => Accept to restore
  • Warning (repeated) = Unresolved dependencies => Accept to restore

Expected Behavior

C# Extensions displays c# code without any errors independent of whether TargetFramework = netcoreapp3.0, 2.2, 2.1, or 2.0.

Actual Behavior

C# Extensions accepts code for 2.0, 2.1, and 2.2.

For netcoreapp3.0 completely different behavior => C# Extensions complains of syntax errors (no type or namespace name) for System, System.String, System.Object, System.Void, etc.

Logs

OmniSharp log

Starting OmniSharp server at 9/23/2019, 11:34:25 PM Target: c:\DEV\OmniDemo

OmniSharp server started. Path: C:\Users\mickr.vscode\extensions\ms-vscode.csharp-1.21.3.omnisharp\1.34.3\OmniSharp.exe PID: 13104

    Starting OmniSharp on Windows 6.2.9200.0 (x64)
    DotNetPath set to dotnet
    Located 2 MSBuild instance(s)
        1: Visual Studio Community 2017 15.9.28307.770 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin"
        2: StandAlone 16.0 - "c:\Users\mickr\.vscode\extensions\ms-vscode.csharp-1.21.3\.omnisharp\1.34.3\.msbuild\Current\Bin"
    MSBUILD_EXE_PATH environment variable set to 'c:\Users\mickr\.vscode\extensions\ms-vscode.csharp-1.21.3\.omnisharp\1.34.3\.msbuild\Current\Bin\MSBuild.exe'
    Registered MSBuild instance: StandAlone 16.0 - "c:\Users\mickr\.vscode\extensions\ms-vscode.csharp-1.21.3\.omnisharp\1.34.3\.msbuild\Current\Bin"
        CscToolExe = csc.exe
        CscToolPath = c:\Users\mickr\.vscode\extensions\ms-vscode.csharp-1.21.3\.omnisharp\1.34.3\.msbuild\Current\Bin\Roslyn
        MSBuildExtensionsPath = c:\Users\mickr\.vscode\extensions\ms-vscode.csharp-1.21.3\.omnisharp\1.34.3\.msbuild
        MSBuildToolsPath = c:\Users\mickr\.vscode\extensions\ms-vscode.csharp-1.21.3\.omnisharp\1.34.3\.msbuild\Current\Bin
    Detecting Cake files in 'c:\DEV\OmniDemo'.
    Could not find any Cake files
    No solution files found in 'c:\DEV\OmniDemo'
    Queue project update for 'c:\DEV\OmniDemo\OmniDemo.csproj'
    Detecting CSX files in 'c:\DEV\OmniDemo'.
    Could not find any CSX files
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
    Loading project: c:\DEV\OmniDemo\OmniDemo.csproj
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.EditorConfigWorkspaceOptionsProvider, Order: 200
    Configuration finished.
    Omnisharp server running using Stdio at location 'c:\DEV\OmniDemo' on host 3140.
    Successfully loaded project file 'c:\DEV\OmniDemo\OmniDemo.csproj'.
    Adding project 'c:\DEV\OmniDemo\OmniDemo.csproj'
    Update project: OmniDemo

[warn]: OmniSharp.MSBuild.PackageDependencyChecker OmniDemo: Did not find ‘Microsoft.NETCore.App’ in lock file. info: OmniSharp.MSBuild.ProjectManager Queue project update for ‘c:\DEV\OmniDemo\OmniDemo.csproj’ info: OmniSharp.MSBuild.ProjectManager Loading project: c:\DEV\OmniDemo\OmniDemo.csproj info: OmniSharp.MSBuild.ProjectManager Successfully loaded project file ‘c:\DEV\OmniDemo\OmniDemo.csproj’. info: OmniSharp.MSBuild.ProjectManager Update project: OmniDemo [warn]: OmniSharp.MSBuild.PackageDependencyChecker OmniDemo: Did not find ‘Microsoft.NETCore.App’ in lock file.

C# log

C# log is EMPTY

Environment information

VSCode version: 1.38.1 C# Extension: 1.21.3

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.0.100 Commit: 04339c3a26

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

Host (useful for support): Version: 3.0.0 Commit: 7d57652f33

.NET Core SDKs installed: 2.1.403 [C:\Program Files\dotnet\sdk] 2.1.500 [C:\Program Files\dotnet\sdk] 2.1.508 [C:\Program Files\dotnet\sdk] 2.2.300 [C:\Program Files\dotnet\sdk] 3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0 [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.3
mssql ms-mssql 1.6.0
remote-wsl ms-vscode-remote 0.39.5
team ms-vsts 1.149.2
vscode-eslint dbaeumer 1.9.1

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 36 (10 by maintainers)

Most upvoted comments

Guys, I’ve got the solution (for those, who don’t want to install VS2019).

  1. Go to Microsoft VS downloads.
  2. Download “Build Tools for Visual Studio 2019”, then install it.
  3. Go to modify -> Individual components, ccheck “.NET Core 3.0 SDK”. Install.
  4. Start your VS Code and have fun.

After it I get this output:

[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 3 MSBuild instance(s)
            1: Visual Studio Professional 2017 15.9.28307.858 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
            2: Visual Studio Build Tools 2019 16.3.29318.209 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
            3: StandAlone 16.0 - "C:\Users\*********\.vscode\extensions\ms-vscode.csharp-1.21.3\.omnisharp\1.34.3\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Visual Studio Build Tools 2019 16.3.29318.209 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"

So correct version of MSBuild is now used by OmniSharp. But don’t forget about step 3, solution need .Net Core 3.0 SDK for VisualStudio.

If you are on Linux or MacOS you may want to try install Mono 6.0.0 https://www.mono-project.com/download/stable/

you could try adding omnisharp.json file:

{
   "MSBuild": {
       "UseLegacySdkResolver": true
   }
}

and see if it helps

Uninstalling all but 3.x and doing the comment by @filipw worked for me on Windows.

you could try adding omnisharp.json file:

{
   "MSBuild": {
       "UseLegacySdkResolver": true
   }
}

and see if it helps

Thanks. It helped! I’m going to try this on my Fedora machine as well. I’m going to uninstall .net core 2 and only have version 3 installed and see if this workaround works there as well.

Thanks a lot for confirming 👍

If anyone experiences this problem on *nix platforms I believer this should help too https://github.com/OmniSharp/omnisharp-vscode/issues/3289#issuecomment-534396993

OmniSharp ships with an embedded MSBuild which for various reasons is somewhat limited - it should work however for more basic scenarios like shown here. If we find VS2019 (Windows) or Mono 5.18.1+ (Linux, MacOS) on the machine, we use that instead.

We are investigating how we can bring the embedded MSBuild up to speed here and what goes wrong there.