Closed gl4eqen closed 4 years ago
Hi. Sorry for writing so late, but hopefully my response still might be helpful to you.
IMHO this appears to be an issue with omnisharp server (or your environment). You are right, that the problematic line in the output is:
[13:13:58] WARNING: OmniSharp.MSBuild.ProjectManager, Failed to load project file '/home/knbr34/dotnet-projects/SampleProj/SampleProj.csproj'.
Sadly, it does not provide any diagnostic info..
My suggestions/questions are:
omnisharp-emacs
and may provide more diagnostics to figure out what is wrong;omnisharp-expected-server-version
variable from "1.32.6" to any from the https://github.com/OmniSharp/omnisharp-roslyn/releases page; maybe there is a fix for you issueI'm getting this without spacemacs, same "Failed to load project file" warning without any more info than that, and only syntactic errors shown. Emacs 26.1 with omnisharp-20181206.21 from melpa, omnisharp server is ~/.emacs.d/.cache/omnisharp/server/v1.32.6/run
.
I do get errors for other projects (e..g there's a tests
project where I get "variable assigned but never used" warnings).
I managed to fix this by doing:
(let ((dotnet-version (string-trim (shell-command-to-string "dotnet --version"))))
(setenv "MSBuildSDKsPath" (format "/opt/dotnet/sdk/%s/Sdks" dotnet-version)))
(Adjust path depending on your distro)
setting MSBuildSDKsPath
(to /usr/share/dotnet/sdk/2.2.101/Sdks
in my case) didn't help me :(
I tried adding "--loglevel" "debug"
in omnisharp--do-server-start
and saw:
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, Attempting to resolve 'Microsoft.Build.resources, Version=15.1.0.0, Culture=nn-NO, PublicKeyToken=b03f5f7f11d50a3a'
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, FAILURE: Could not locate '/home/unhammer/.emacs.d/.cache/omnisharp/server/v1.32.8/omnisharp/msbuild/15.0/Bin/Microsoft.Build.resources.dll'.
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, Attempting to resolve 'Microsoft.Build.resources, Version=15.1.0.0, Culture=nn, PublicKeyToken=b03f5f7f11d50a3a'
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, FAILURE: Could not locate '/home/unhammer/.emacs.d/.cache/omnisharp/server/v1.32.8/omnisharp/msbuild/15.0/Bin/Microsoft.Build.resources.dll'.
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, Attempting to resolve 'Microsoft.Build.resources, Version=15.1.0.0, Culture=no, PublicKeyToken=b03f5f7f11d50a3a'
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, FAILURE: Could not locate '/home/unhammer/.emacs.d/.cache/omnisharp/server/v1.32.8/omnisharp/msbuild/15.0/Bin/Microsoft.Build.resources.dll'.
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, Attempting to resolve 'Microsoft.Build.resources, Version=15.1.0.0, Culture=nn-NO, PublicKeyToken=b03f5f7f11d50a3a'
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, FAILURE: Could not locate '/home/unhammer/.emacs.d/.cache/omnisharp/server/v1.32.8/omnisharp/msbuild/15.0/Bin/Microsoft.Build.resources.dll'.
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, Attempting to resolve 'Microsoft.Build.resources, Version=15.1.0.0, Culture=nn, PublicKeyToken=b03f5f7f11d50a3a'
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, FAILURE: Could not locate '/home/unhammer/.emacs.d/.cache/omnisharp/server/v1.32.8/omnisharp/msbuild/15.0/Bin/Microsoft.Build.resources.dll'.
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, Attempting to resolve 'Microsoft.Build.resources, Version=15.1.0.0, Culture=no, PublicKeyToken=b03f5f7f11d50a3a'
[12:35:49] DEBUG: OmniSharp.MSBuild.Discovery.MSBuildLocator, FAILURE: Could not locate '/home/unhammer/.emacs.d/.cache/omnisharp/server/v1.32.8/omnisharp/msbuild/15.0/Bin/Microsoft.Build.resources.dll'.
[12:35:49] WARNING: OmniSharp.MSBuild.ProjectManager, Failed to load project file '/home/unhammer/src/Systor.M3WebServices/WSProject/WSProject.csproj'.
There's no such file in .emacs.d/.cache/omnisharp/server/v1.32.8/omnisharp/msbuild/15.0/Bin/, although it exists in e.g. /usr/share/dotnet/sdk/2.2.101/en/Microsoft.Build.resources.dll
. If I $ cp /usr/share/dotnet/sdk/2.2.101/en/Microsoft.Build.resources.dll ~/.emacs.d/.cache/omnisharp/server/v1.32.8/omnisharp/msbuild/15.0/Bin/
it still doesn't work (though it says SUCCESS where it above said FAILURE, I still get Failed to load project file
).
You should try setting (setq omnisharp-debug t)
and then look into OmniServer
buffer to see server's output.
I at least see that .emacs.d/.cache/omnisharp/server/v1.32.8/lib/mono/xbuild/Microsoft/VisualStudio/v15.0/WebApplications/Microsoft.WebApplication.targets\" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
This file exists in /usr/lib/mono/xbuild/Microsoft/VisualStudio/v15.0/WebApplications/Microsoft.WebApplication.targets
.
When I do /usr/bin/msbuild
from the command line, it builds fine and seems to use that file.
(let ((dotnet-version (string-trim (shell-command-to-string "dotnet --version")))) (setenv "MSBuildSDKsPath" (format "/opt/dotnet/sdk/%s/Sdks" dotnet-version)))
by @TatriX
This solution PLUS installing msbuild-stable from AUR on Arch Linux helped. I hate those bugs which are a result of incompatibilities between versions. I hope this get fixed somehow in further releases.
I don't really get why dotnet-core eventually depends on Mono. They are completely separate projects. It seems they share the same builder - MSBuild/XBuild ??, this seems to be so complicated, I'd love someone to explain me all those dotnet core / .NET internals :(
Debug outputs in order of applied fixes: Before setting env var MSBuildSDKsPath
After setting env var MSBuildSDKsPath
After installing msbuild-stable
PS. I did
2. try to change
omnisharp-expected-server-version
variable from "1.32.6" to any from the https://github.com/OmniSharp/omnisharp-roslyn/releases page; maybe there is a fix for you issue
just to be sure I have newest version of omnisharp server running.
I'm on Ubuntu, so there's no msbuild-stable package, but I do have mono-complete
from https://www.mono-project.com/download/stable/ which includes msbuild version 1:16.0+xamarinxplat.2018.09.26.17.53-0xamarin3+ubuntu1804b1
.
But it seems your error from missing msbuild-stable
was
{"Event":"Error","Body":{"Text":"Microsoft.Build.Exceptions.InvalidProjectFileException:
The imported project \"/usr/lib/mono/xbuild/15.0/Microsoft.Common.props\" was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
/opt/dotnet/sdk/2.2.100/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props
while without the MSBuildSDKsPath
env var it was:
{"Event":"Error","Body":{"Text":"Microsoft.Build.Exceptions.InvalidProjectFileException:
The SDK 'Microsoft.NET.Sdk' specified could not be found.
A workaround for my
emacs.d/.cache/omnisharp/server/v1.32.8/lib/mono/xbuild/Microsoft/VisualStudio/v15.0/WebApplications/Microsoft.WebApplication.targets\" was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
was to
cd ~/.emacs.d/.cache/omnisharp/server/v1.32.8/lib/mono/
ln -s /usr/lib/mono/xbuild
– but shouldn't omnisharp have found that path when /usr/bin/msbuild
finds it? Or does omnisharp use a different msbuild from the one installed by mono?
@unhammer Ok, now I get it. You CAN'T have mono installed without msbuild-stable when using dotnet-core. Apparently omnisharp searches for toolchain and finds mono (if it is installed) before dotnet-core. If you have dotnet-core only, only setting environment variable is needed.
msbuild-stable adds files to mono directories which (accidentally?) match dotnet-core toolchain. This is why workaround works.
I'm using Omnisharp within csharp layer of Spacemacs. It works pretty well apart from error detection. It doesn't see anything more sophisticated than missing coma: lacking namespace import, typo in method name etc. Neither omnisharp-solution-errors nor flycheck show anything useful.
This line seems worrying from omnisharp log:
[13:13:58] WARNING: OmniSharp.MSBuild.ProjectManager, Failed to load project file '/home/knbr34/dotnet-projects/SampleProj/SampleProj.csproj'.
Is my configuration wrong? Omnisharp version: 20181023.505 from melpa Manual build bydotnet build
behaves correctly.Possibly helpful files: *omnisharp-log* with omnisharp-debug set to 't'
SampleProj.csproj
dotnet-projects.sln (I wondered if this happens only with solutionless projects so I created solution but it doesn't change a thing)
Program.cs (visible in first log but whatever)