OmniSharp / omnisharp-roslyn

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

Fails with projects that contain a reference to RoslynCodeTaskFactory #2127

Open dalealleshouse opened 3 years ago

dalealleshouse commented 3 years ago

Issue Description

OmniSharp fails to load projects that reference nuget packages with RoslynCodeTaskFactory tasks. The project builds and runs fine but the following error appears in the log file:

[fail]: OmniSharp.MSBuild.ProjectLoader
        "csc.exe" exited with code 1.

Steps to Reproduce

For convivence, I created a very simple project that demonstrates the problem: https://github.com/dalealleshouse/omnisharp-demo

git clone https://github.com/dalealleshouse/omnisharp-demo

# notice there are two projects, NetCoreProject and OmniSharpDemo.FileGenerator
# The later is source for a nuget package that's published here: https://www.nuget.org/packages/OmniSharpDemo.FileGenerator/2.0.1
cd omnisharp-demo

# This will pull the nuget package
dotnet restore
dotnet build

Open the project in your editor or choice to see the error (I've tried omnisharp-vim and omnisharp-vscode)

Expected Behavior

OmniSharp should load the project

Actual Behavior

OmniSharp generates an error in the log and does not load the project

Logs

VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 15 2020 06:40:31), Included patches: 1-2269

OmniSharp server started.
    Path: /home/dalealleshouse/.cache/omnisharp-vim/omnisharp-roslyn/run
    Target: /home/dalealleshouse/src/omnisharp-demo/omnisharp-demo.sln
    PID: 13127

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on ubuntu 20.4 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 16.9.0 - "/home/dalealleshouse/.cache/omnisharp-vim/omnisharp-roslyn/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to '/home/dalealleshouse/.cache/omnisharp-vim/omnisharp-roslyn/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 16.9.0 - "/home/dalealleshouse/.cache/omnisharp-vim/omnisharp-roslyn/omnisharp/.msbuild/Current/Bin"
            CscToolExe = csc.exe
            MSBuildToolsPath = /home/dalealleshouse/.cache/omnisharp-vim/omnisharp-roslyn/omnisharp/.msbuild/Current/Bin
            CscToolPath = /home/dalealleshouse/.cache/omnisharp-vim/omnisharp-roslyn/omnisharp/.msbuild/Current/Bin/Roslyn
            BypassFrameworkInstallChecks = true
            MSBuildExtensionsPath = /home/dalealleshouse/.cache/omnisharp-vim/omnisharp-roslyn/omnisharp/.msbuild
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
[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.ImplementTypeWorkspaceOptionsProvider, Order: 110
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/home/dalealleshouse/src/omnisharp-demo'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/home/dalealleshouse/src/omnisharp-demo/omnisharp-demo.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/home/dalealleshouse/src/omnisharp-demo/OmniSharpDemo.FileGenerator/OmniSharpDemo.FileGenerator.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/home/dalealleshouse/src/omnisharp-demo/NetCoreProject/NetCoreProject.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/home/dalealleshouse/src/omnisharp-demo'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/home/dalealleshouse/src/omnisharp-demo' on host -1.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /home/dalealleshouse/src/omnisharp-demo/OmniSharpDemo.FileGenerator/OmniSharpDemo.FileGenerator.csproj
[info]: OmniSharp.OmniSharpWorkspace
        Miscellaneous file: /home/dalealleshouse/src/omnisharp-demo/NetCoreProject/Program.cs added to workspace
Replaying requests for buffer 3
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/home/dalealleshouse/src/omnisharp-demo/OmniSharpDemo.FileGenerator/OmniSharpDemo.FileGenerator.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/home/dalealleshouse/src/omnisharp-demo/OmniSharpDemo.FileGenerator/OmniSharpDemo.FileGenerator.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /home/dalealleshouse/src/omnisharp-demo/NetCoreProject/NetCoreProject.csproj
[fail]: OmniSharp.MSBuild.ProjectLoader
        "csc.exe" exited with code 1.
[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file '/home/dalealleshouse/src/omnisharp-demo/NetCoreProject/NetCoreProject.csproj'.
All projects loaded
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: OmniSharpDemo.FileGenerator
[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: /home/dalealleshouse/src/omnisharp-demo/NetCoreProject/NetCoreProject.csproj
Workspace complete: 2 project(s)
Replaying on-load requests

Environment Information

WSL2 running on Windows - ubuntu 20.4 (x64) OmniSharp-Roslyn v1.37.8

Installed SDKs

Voltara commented 1 year ago

As a workaround, you can create a shell script named /usr/share/dotnet/sdk/X.Y.ZZZ/Roslyn/csc.exe

#! /bin/sh
exec dotnet "`dirname \"$0\"`/bincore/csc.dll" "$@"

Update: Although the above gets OmniSharp working, it breaks other things like dotnet build, which means it's not at all useful.

One thing that does seem to work is to chmod+x .../Roslyn/bincore/csc.dll, and use the binfmt_misc kernel facility to specify an interpreter for .Net DLLs. If you have the binfmt-support package installed, create the file /usr/share/binfmts/dotnet:

package dotnet
interpreter /usr/bin/dotnet
magic MZ
detector /path/to/dotnet-detector

The dotnet-detector script should check that the file being executed is actually a .Net assembly. For example:

#! /bin/sh
exec file -b -- "$1" | grep -F "Mono/.Net assembly" 2>/dev/null

Then run sudo update-binfmts --import dotnet to activate the new configuration.