razzmatazz / csharp-language-server

Roslyn-based LSP language server for C#
MIT License
591 stars 38 forks source link

Can't find SDK and Nuget symbols on Windows project in MacOS #93

Open martin-braun opened 1 year ago

martin-braun commented 1 year ago

I have a rich VisualStudio solution (6 projects, a lot of Nuget Packages, WPF and Windows target exclusive) that I wish to edit and explore on MacOS (no building requirement). I use Neovim 8 with coc-nvim and I have dotnet and its framework 7 installed. I configured my language server as mentioned in other issues here in my coc-settings.json after installing csharp-ls.

I can run csharp-ls -s MySolution.sln without errors.

My coc-settings.json contains:

  "languageserver": {
    "csharp-ls": {
      "command": "csharp-ls",
      "filetypes": ["cs"],
      "rootPatterns": ["*.csproj", ".vim/", ".git/", ".hg/"]
    }
  },

When I open a .cs file I get:

[coc.nvim] csharp-ls: csharp-ls is released under MIT license and is not affiliated with Microsoft Corp.; see https://github.com/razzmatazz/csh
arp-language-server
[coc.nvim] csharp-ls: MSBuildLocator: will register ".NET Core SDK", Version=7.0.203 as default instance
[coc.nvim] csharp-ls: attempting to find and load solution based on cwd ("/AAA")..
[coc.nvim] csharp-ls: 1 solution(s) found: [/AAA/Ceto.AAA.sln]
[coc.nvim] csharp-ls: loading solution "/AAA/Ceto.AAA.sln"..
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Failure] Msbuild failed when processing the file '/AAA/Ceto.AAA.UI/Ceto.AAA.UI.csproj' with message: /usr/local/share/dotnet/sdk/7.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.Framew
orkReferenceResolution.targets: (90, 5): To build a project targeting Windows on this operating system, set the EnableWindowsTargeting property
 to true.
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Failure] Msbuild failed when processing the file '/AAA/Ceto.AAA.UI/Ceto.AAA.UI.csproj' with message: /usr/local/share/dotnet/sdk/7.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.Framew
orkReferenceResolution.targets: (90, 5): To build a project targeting Windows on this operating system, set the EnableWindowsTargeting property
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Failure] Msbuild failed when processing the file '/AAA/Ceto.AAA.Core.csproj' with message: /usr/local/share/dotnet/sdk/7.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDep
endencyResolution.targets: (266, 5): The "ResolvePackageAssets" task failed unexpectedly.
NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages'.
   at NuGet.Packaging.FallbackPackagePathResolver..ctor(String userPackageFolder, IEnumerable`1 fallbackPackageFolders)
   at Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver(IEnumerable`1 packageFolders)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext,
TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Warning] Found project reference without a matching metadata reference: /AAA/Ceto.AAA.Core/Ceto.AAA.Core.csproj
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Failure] Msbuild failed when processing the file '/AAA/Ceto.AAA.WPF/Ceto.AAA.WPF.csproj' with message: /usr/local/share/dotnet/sdk/7.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.Fram
eworkReferenceResolution.targets: (90, 5): To build a project targeting Windows on this operating system, set the EnableWindowsTargeting proper
ty to true.
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Warning] Found project reference without a matching metadata reference: /AAA/Ceto.AAA.WPF/Ceto.AAA.WPF.csproj
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Failure] Msbuild failed when processing the file '/AAA/Ceto.AAA.Daemon/Ceto.AAA.Daemon.csproj' with message: /usr/local/share/dotnet/sdk/7.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sd
k.FrameworkReferenceResolution.targets: (90, 5): To build a project targeting Windows on this operating system, set the EnableWindowsTargeting
property to true
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Failure] Msbuild failed when processing the file '/AAA/Ceto.AAA.Config/Ceto.AAA.Config.csproj' with message: /usr/local/share/dotnet/sdk/7.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sd
k.FrameworkReferenceResolution.targets: (90, 5): To build a project targeting Windows on this operating system, set the EnableWindowsTargeting
property to true.
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Warning] Found project reference without a matching metadata reference: /AAA/Ceto.AAA.Core/Ceto.AAA.Core.csproj
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Warning] Found project reference without a matching metadata reference: /AAA/Ceto.AAA.WPF/Ceto.AAA.WPF.csproj
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Warning] Found project reference without a matching metadata reference: /AAA/Ceto.AAA.Config/Ceto.AAA.Config.csproj
[coc.nvim] csharp-ls: msbuildWorkspace.Diagnostics: [Warning] Found project reference without a matching metadata reference: /AAA/Ceto.AAA.UI/Ceto.AAA.UI.csproj
[coc.nvim] csharp-ls: finished loading solution "/AAA/Ceto.AAA.sln"

In the CS files it fails to find symbols for the SDK or any NuGet packages:

Screen Shot 2023-05-21 at 02 37 37

I don't understand why it complains about my target, when I don't even attempted to build. I just want to explore and modify, but I will compile in Parallels. It also searches for NuGet packages in the Windows location. Is it even possible to get linting, suggestions and go-to-definitions to work on MacOO properly without breaking the project on Windows?

The navigation seem to work fine for my own classes. Thanks.

martin-braun commented 1 year ago

I now had to port the project from .NET Core 5 to .NET Framework 4.8.1 (Windows only). Is there a way to get navigation, tool tips and all to work anyways? I'm not aware that my local dotnet version didn't match my projects dotnet version, but does the Roselyn server can understand the .NET Framework from any platform, despite building is only possible on Windows?