OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.78k stars 419 forks source link

Is it possible to make 'dotnet framework missing' a warning rather than error on mac/linux? #1253

Open DustinCampbell opened 6 years ago

DustinCampbell commented 6 years ago

From @CaulyKan on July 31, 2018 16:7

Environment data

dotnet --info output: .NET Core SDK (reflecting any global.json): Version: 2.1.302 Commit: 9048955601

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

Host (useful for support): Version: 2.1.2 Commit: 811c3ce6c0

.NET Core SDKs installed: 2.1.302 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

VS Code version: 1.25.1 C# Extension version: 1.15.2

Steps to reproduce

Create a project:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net461;net452;netstandard2.0</TargetFrameworks>
    <DebugType>Full</DebugType>
  </PropertyGroup>

</Project>

Expected behavior

Omnisharp gives a warning rather than error for "The reference assemblies for framework ".NETFramework,Version=v4.6.1" were not found. "; Functions such as codelens should still be functional.

Actual behavior

Omnisharp gives an error for "The reference assemblies for framework ".NETFramework,Version=v4.6.1" were not found. "; Functions such as codelens no longer works.

Copied from original issue: OmniSharp/omnisharp-vscode#2444

DustinCampbell commented 6 years ago

The issue here is that OmniSharp picks the first target framework when there are multiple TFMs. So, it's MSBuild is trying process your project as net461, but that isn't installed on your Mac. There are a couple of options here:

  1. Reorder the TFMs so that netstandard2.0 is first.
  2. Install reference assemblies for .NET Framework 4.6.1 in a place that MSBuild can discover them. The easiest way to do this is by installing the latest Mono MDK from http://www.mono-project.com/download/stable/.
DustinCampbell commented 6 years ago

From @CaulyKan on July 31, 2018 17:35

After changed the csproj to <TargetFrameworks>netstandard2.0;net461;net452</TargetFrameworks> it worked.

But however is it possible to try the next TFM in order when the current one fails? or more easily, write the instruction in error message?

Thanks a lot.

PS. Current error message: The reference assemblies for framework ".NETFramework,Version=v4.6.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

DustinCampbell commented 6 years ago

It's harder than you might think to detect this scenario. The message actually comes from MSBuild as part of the process of building your project. However, I think we should probably try to do something. I'll move this over to the omnisharp-roslyn repo where that work would need to happen.

ethomson commented 6 years ago

Could there be some mechanism (environment variable, configuration file, etc) that allows me to specify the framework that I want to use?