vscode-csharp: ProjectReference results in "type or namespace name 'System' could not be found" when Multi-Trageting

Environment data

dotnet --info output:

.NET Command Line Tools (2.1.4)

Product Information:
 Version:            2.1.4
 Commit SHA-1 hash:  5e8add2190

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.12
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.1.4/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.5
  Build    : 17373eb129b3b05aa18ece963f8795d65ef8ea54

VS Code version: 1.20.1

C# Extension version: 1.14.0

Steps to reproduce

1- Create a mstest project 2- Open the folder in VS Code; verify there are no errors; Close the Folder 3- use DOTNET ADD to add a ProjectReference outside of root directory to the mstest project. The Reference Project must have use TargetFrameworks (multi-Target) not TargetFramework. 4- Open the folder in VS Code;

Expected behavior

No Problems/Error given that “dotnet build” works.

Actual behavior

Problem Panel displays lots of errors

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 26 (10 by maintainers)

Most upvoted comments

Sorry how do we get this version in vscode? I’m on windows and see 1.17.1 for the c# extension. It appears to have omnisharp 1.31+, but it still can’t pick up using System and tons of errors.

Here is my OmniSharp output

Starting OmniSharp server at 1/8/2019, 2:58:03 PM
    Target: c:\Users\user\Source\project_root\project_name.sln

OmniSharp server started.
    Path: C:\Users\user\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\OmniSharp.exe
    PID: 11172

[info]: OmniSharp.Stdio.Host
        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 Professional 2017 15.6.27428.2002 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
            2: StandAlone 15.0 - "C:\Users\user\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Visual Studio Professional 2017 15.6.27428.2002 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in 'c:\Users\user\Source\project_root'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.WorkspaceInitializer
        Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in 'c:\Users\user\Source\project_root\project_name.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for 'c:\Users\user\Source\project_root\project_name\project_name.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'c:\Users\user\Source\project_root'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: c:\Users\user\Source\project_root\project_name\project_name.csproj
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location 'c:\Users\user\Source\project_root' on host 21164.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file 'c:\Users\user\Source\project_root\project_name\project_name.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project 'c:\Users\user\Source\project_root\project_name\project_name.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: project_name

No, there’s no way to do that. OmniSharp really only calls the Compile and CoreCompile targets, which depend on a lot of other targets. I suspect that disabling some would mean that things just don’t work.

I’ve made a few fixes to OmniSharp in this area recently. In particular, we identified a problem where it would fail to handle multi-targeted projects that were referenced outside of the current solution or folder that OmniSharp was launched with. Could you try using that version and see if it helps with this particular issue? You can use it by setting "omnisharp.path" to "latest" in the VS Code settings.