omnisharp-roslyn icon indicating copy to clipboard operation
omnisharp-roslyn copied to clipboard

Referenced F# projects are not working

Open DustinCampbell opened this issue 7 years ago • 24 comments

DustinCampbell avatar Nov 08 '17 14:11 DustinCampbell

Simple repro:

dotnet new classlib --name f --language f# && dotnet new console --name c && dotnet add c/c.csproj reference f/f.fsproj && dotnet new sln && dotnet sln add f/f.fsproj && dotnet sln add c/c.csproj && dotnet build && code .

now add

f.Say.hello("foo"); into Main in Program.cs

dotnet run -p c/c.csproj runs fine

However in vscode I get an intelisense error: 'The name 'f' does not exist in the current context [c]'

mrgleba avatar Nov 08 '17 14:11 mrgleba

And the OmniSharp Log:

Starting OmniSharp server at 2017-11-8 15:22:25
    Target: /mnt/code4/code4.sln

OmniSharp server started wth Mono
    Path: /home/gleba/.vscode/extensions/ms-vscode.csharp-1.13.0/.omnisharp/run
    PID: 3558

[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 15.0 - "/home/gleba/.vscode/extensions/ms-vscode.csharp-1.13.0/.omnisharp/omnisharp/msbuild/15.0/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to '/home/gleba/.vscode/extensions/ms-vscode.csharp-1.13.0/.omnisharp/omnisharp/msbuild/15.0/Bin/MSBuild.dll'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 15.0 - "/home/gleba/.vscode/extensions/ms-vscode.csharp-1.13.0/.omnisharp/omnisharp/msbuild/15.0/Bin"
            MSBuildExtensionsPath = /home/gleba/.vscode/extensions/ms-vscode.csharp-1.13.0/.omnisharp/omnisharp/msbuild
            CscToolPath = /home/gleba/.vscode/extensions/ms-vscode.csharp-1.13.0/.omnisharp/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
            MSBuildToolsPath = /home/gleba/.vscode/extensions/ms-vscode.csharp-1.13.0/.omnisharp/omnisharp/msbuild/15.0/Bin
            TargetFrameworkRootPath = /usr/lib/mono/xbuild-frameworks
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/mnt/code4'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Initializing in /mnt/code4
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Auto package restore: False
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Update workspace context
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Resolving projects references
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Detecting projects in '/mnt/code4/code4.sln'.
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Loading project: /mnt/code4/c/c.csproj
[fail]: OmniSharp.MSBuild.ProjectFile.ProjectFileInfo
        The target "GetTargetPath" does not exist in the project.
/mnt/code4/c/c.csproj

[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Update project: c
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/mnt/code4'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.Stdio.Program
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.Stdio.Program
        Configuration finished.
[info]: OmniSharp.Stdio.Program
        Omnisharp server running using Stdio at location '/mnt/code4' on host 3470.

mrgleba avatar Nov 08 '17 14:11 mrgleba

@mrgleba : I cannot repro this on my Mac using your repro steps.

image

That said, I suspect that the problem you're running into is not related to this particular issue. Given the error in your project:

The target "GetTargetPath" does not exist in the project.
/mnt/code4/c/c.csproj

What Linux distro/version are you running?

DustinCampbell avatar Nov 08 '17 16:11 DustinCampbell

I can repro on both Fedora 26 and Windows 10.

mrgleba avatar Nov 08 '17 20:11 mrgleba

To be clear, this is a very different problem than this particular GitHub issue. :smile:

DustinCampbell avatar Nov 08 '17 21:11 DustinCampbell

FWIW, I can repro the issue you're describing on OSX if I delete Mono. My theory is that additional MSBuild logic is required to process F# projects. The .NET Core SDK includes these MSBuild targets and tasks, but OmniSharp does not because OmniSharp is C#-only. So, in order to get this working, you should do one of the following:

  1. On Fedora, upgrade to the latest Mono. OmniSharp will use Mono's MSBuild targets and tasks the version of Mono is 5.2.0 or greater. However, on Fedora 26, the available Mono is 4.8.0. You can install the latest CentOS 7 packages from http://www.mono-project.com/download/#download-lin-centos on Fedora 26.
  2. On Windows 10, I'm guessing that you don't have any flavor of VS 2017 installed, correct? VS 2017 or the VS 2017 Build Tools would normally contain the F# support necessary. Try installing the VS 2017 Build Tools (https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017) and be sure to check any boxes for F# when you do so.

DustinCampbell avatar Nov 08 '17 21:11 DustinCampbell

I've done some digging on Linux. After installing mono 5.4 Omnisharp throws an error complaining it's unable to load Microsoft.Build.Framework & Microsoft.Build. I've pulled those (tried 15.1 and newest) from nuget and now it throws

System.PlatformNotSupportedException: Operation is not supported on this platform.
  at Microsoft.Build.Shared.BuildEnvironmentHelper.get_Instance () [0x00017] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.Shared.NativeMethodsShared.get_IsMono () [0x00033] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.BackEnd.Logging.LoggingService..ctor (Microsoft.Build.BackEnd.Logging.LoggerMode loggerMode, System.Int32 nodeId) [0x00039] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.BackEnd.Logging.LoggingService.CreateLoggingService (Microsoft.Build.BackEnd.Logging.LoggerMode mode, System.Int32 node) [0x00000] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.Evaluation.ProjectCollection.CreateLoggingService (System.Int32 maxCPUCount, System.Boolean onlyLogCriticalEvents) [0x00000] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.Evaluation.ProjectCollection..ctor (System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.Collections.Generic.IEnumerable`1[T] loggers, System.Collections.Generic.IEnumerable`1[T] remoteLoggers, Microsoft.Build.Evaluation.ToolsetDefinitionLocations toolsetDefinitionLocations, System.Int32 maxNodeCount, System.Boolean onlyLogCriticalEvents) [0x0011d] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.Evaluation.ProjectCollection..ctor (System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.Collections.Generic.IEnumerable`1[T] loggers, Microsoft.Build.Evaluation.ToolsetDefinitionLocations toolsetDefinitionLocations) [0x00000] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.Evaluation.ProjectCollection..ctor (System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties) [0x00000] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.LoadProject (System.String filePath, System.String solutionDirectory, Microsoft.Extensions.Logging.ILogger logger, OmniSharp.MSBuild.Discovery.MSBuildInstance msbuildInstance, OmniSharp.Options.MSBuildOptions options, System.Collections.Generic.ICollection`1[T] diagnostics, System.Collections.Immutable.ImmutableArray`1[System.String]& targetFrameworks) [0x00017] in <b33b7bcd685c4ae4bb5069e4d26c1bf0>:0 
  at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Create (System.String filePath, System.String solutionDirectory, Microsoft.Extensions.Logging.ILogger logger, OmniSharp.MSBuild.Discovery.MSBuildInstance msbuildInstance, OmniSharp.Options.MSBuildOptions options, System.Collections.Generic.ICollection`1[T] diagnostics) [0x0000a] in <b33b7bcd685c4ae4bb5069e4d26c1bf0>:0 
  at OmniSharp.MSBuild.MSBuildProjectSystem.LoadProject (System.String projectFilePath) [0x00038] in <b33b7bcd685c4ae4bb5069e4d26c1bf0>:0 

My hunch is https://github.com/Microsoft/msbuild/commit/9654902b70e22eccc8105efdac5060c7d7adaa1a#diff-7dd0925e4fa31af6856e773c2c80a62c broke the IsMono on Linux.

What version of msbuild is shipped with omnisharp?

mrgleba avatar Nov 09 '17 11:11 mrgleba

I've installed VS 2017 & build tools on Windows. However omnisharpd doesn't seem to find them. I've tried to set the MSBUILD_EXE_PATH variable but to no avail.

mrgleba avatar Nov 09 '17 12:11 mrgleba

Linux:

It's not clear to me what you pulled from Linux and where you've put them. The NuGet version are not used on Linux because they are generally intended for Windows. Since you've got Mono 5.4 installed, I would have been interested to see your OmniSharp Log when it couldn't locate Microsoft.Build.dll.

Windows:

Setting MSBUILD_EXE_PATH variable won't be of help here. Instead, could your provide your OmniSharp Log on Windows?

DustinCampbell avatar Nov 09 '17 13:11 DustinCampbell

Windows:

Starting OmniSharp server at 2017-11-9 14:33:55
    Target: f:\code4\c

OmniSharp server started
    Path: C:\Users\gleba\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\OmniSharp.exe
    PID: 10752

[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 15.0 - "C:\Users\gleba\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to 'C:\Users\gleba\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 15.0 - "C:\Users\gleba\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin"
            CscToolExe = csc.exe
            CscToolPath = C:\Users\gleba\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Roslyn
            MSBuildExtensionsPath = C:\Users\gleba\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild
            MSBuildToolsPath = C:\Users\gleba\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in 'f:\code4\c'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Initializing in f:\code4\c
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Auto package restore: False
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Update workspace context
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Resolving projects references
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        No solution files found in 'f:\code4\c'
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Loading project: f:\code4\c\c.csproj
[fail]: OmniSharp.MSBuild.ProjectFile.ProjectFileInfo
        The target "GetTargetPath" does not exist in the project.
f:\code4\c\c.csproj

[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Update project: c
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'f:\code4\c'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.Stdio.Program
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.Stdio.Program
        Configuration finished.
[info]: OmniSharp.Stdio.Program
        Omnisharp server running using Stdio at location 'f:\code4\c' on host 10132.

mrgleba avatar Nov 09 '17 13:11 mrgleba

That's with the VS 2017 Build Tools installed?

DustinCampbell avatar Nov 09 '17 13:11 DustinCampbell

Both VS 2017 and build tools (latest ver)

mrgleba avatar Nov 09 '17 13:11 mrgleba

Hmmm.... IIRC, F# support is not installed by default. I believe that's a separate checkbox in the installer under "Individual Components". Did you install F# support with them?

DustinCampbell avatar Nov 09 '17 14:11 DustinCampbell

Note: I've re-titled this issue and re-filed the original backlog item since the issue is pretty thoroughly hijacked by now.

DustinCampbell avatar Nov 09 '17 14:11 DustinCampbell

C# and F# installed in both VS2017 and build tools

mrgleba avatar Nov 09 '17 14:11 mrgleba

and MSBuild installed in VS2017

mrgleba avatar Nov 09 '17 14:11 mrgleba

FWIW, I'm spinning up clean Windows 10 VM right now so I can try it with the build tools.

DustinCampbell avatar Nov 09 '17 14:11 DustinCampbell

I was finnaly able to resolve on Linux. After installing missing msbuild the assemlby load error was gone and the "GetTargetPath" error was back. I was also missing the fsharp package. After installing them everything is fine.

So perhaps on Windows the "GetTargetPath" message is also related to finding f# path?

mrgleba avatar Nov 10 '17 11:11 mrgleba

I found the msbuild package as well and didn't realize that fsharp was different. Thanks for spotting that!

For Windows, yes, the problem is that it can't locate the MSBuild targets and tasks necessary for F#. Could you provide the OmniSharp Log on Windows for me now that you've installed the VS 2017 build tools?

DustinCampbell avatar Nov 10 '17 14:11 DustinCampbell

The previous log was after everything was installed

mrgleba avatar Nov 10 '17 14:11 mrgleba

Ah OK. Well, in that case, it looks like it isn't finding the install of the VS 2017 build tools at all. Hmmm...

DustinCampbell avatar Nov 10 '17 14:11 DustinCampbell

I don't know if I understand the current solution. I'm on a mac. I just need to install standalone mono?

mikehaas763 avatar Nov 24 '17 23:11 mikehaas763

@mikehaas763 : Ensure that you install the full Mono MDK. You can do this using Homebrew using brew install cask mono-mdk or by downloading the latest installer from http://www.mono-project.com/download/#download-mac.

DustinCampbell avatar Nov 25 '17 15:11 DustinCampbell

@DustinCampbell Still have a problem with the f#. Is there any update on this issue?

jungyu-rim avatar Apr 17 '22 18:04 jungyu-rim