vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Will omnisharp.json still be supported?

Open Looka997 opened this issue 2 years ago • 11 comments

I'm developing a container image where a directory is specified in the omnisharp.json to host code refactoring dlls, so they can be discovered by omnisharp. Will it still work in the new extension? Will it only work if I set dotnet.server.useOmnisharp to true?

Looka997 avatar Jun 29 '23 18:06 Looka997

The omnisharp.json file itself is associated with the O# server. It will only work in the new version of the extension if you're using O# (setting dotnet.server.useOmnisharp to true as you mention). omnisharp.json will not be supported in the new LSP server.

However - in the new LSP server we should still support loading additional code refactorings via nuget package references in your project, but we have not yet decided if we're going to support directly loading additional dlls directly in the extension.

Is the nuget packages support good enough for you, or is there a specific scenario where you can't reference them via nuget package and directly need to load them in the extension?

dibarbet avatar Jun 29 '23 21:06 dibarbet

Since I was mistakenly under the impression that deploying code refactorings with NuGet packages was not possibile, I was adding them through omnisharp.json. Although https://github.com/dotnet/roslyn/pull/35685 seems to suggest the contrary, I can't find a simple example of this.

Yes, NuGet package support is in fact enough, can't get it to work though - and I apologize since this is not the correct repo to ask this - but can you throw me a bone? Packaging them to a NuGet package's analyzers/dotnet/cs does not seems to do the trick, even though analyzers .dlls in the very same directory get discovered just fine.

Looka997 avatar Jun 30 '23 09:06 Looka997

This is an area I'm not as familiar with to be honest, so I'll tag in @sharwell to help answer how to deploy refactorings in a nuget package.

dibarbet avatar Jun 30 '23 18:06 dibarbet

They are deployed identically to code fixes in analyzer packages. If you have an example package which is causing problems I could take a look and see if anything stands out.

sharwell avatar Jun 30 '23 20:06 sharwell

They are deployed identically to code fixes in analyzer packages. If you have an example package which is causing problems I could take a look and see if anything stands out.

Made up an ugly example, but easily reproducible: replacing the code refactoring from the "Code Refactoring (.NET Standard)" template to the code fix in the template "Analyzer with Code Fix (.NET Standard)". The latter would normally deploy fine both to VSIX and NuGet. With the code refactoring in place of the code fix, it only deploys successfully to VSIX. As NuGet package, it is placed under the analyzers section as it is packaged to "analyzers/dotnet/cs", but the UI prompting the refactor won't show up. Am I missing something?

Looka997 avatar Jul 05 '23 17:07 Looka997

I use the omnisharp.json file to define the location of an RSP file to load an assembly, in a scripting project context (csx): /r:"C:/Program Files/MySoft/MyLibrary.dll" How can I do this without using an O# server? Thanks.

CyberSinh avatar Jul 20 '23 09:07 CyberSinh

I have a scripting scenario as well.. Would be nice if we could specify additional references in an array in some .vscode .json file.. That way we could use environment variables instead of hardcoding absolute paths which change per machine.

LostTime76 avatar Aug 25 '23 23:08 LostTime76

we have not yet decided if we're going to support directly loading additional dlls directly in the extension

@dibarbet This may be the only way to get analyzer nuget packages to work in a Unity project. There is a way to set up these DLLs as Unity assets (https://docs.unity3d.com/2023.3/Documentation/Manual/roslyn-analyzers.html) but I am not sure that it would result in those analyzers being reported in VSCode.

Besides it's a pain to download these packages and reference the DLLs manually, but I understand that may be something for Unity to address and not the VSCode C# extension.

marcospgp avatar Oct 03 '23 13:10 marcospgp

@dibarbet This may be the only way to get analyzer nuget packages to work in a Unity project. There is a way to set up these DLLs as Unity assets (https://docs.unity3d.com/2023.3/Documentation/Manual/roslyn-analyzers.html) but I am not sure that it would result in those analyzers being reported in VSCode.

Hmm, I don't know how that works exactly - @jbevain do you know if analyzers added in unity by the above method get added to the generated csproj as well (maybe as <Analyzer> nodes?)

dibarbet avatar Oct 03 '23 17:10 dibarbet

I wasn't able to get analyzer DLLs to work with Unity so gave up entirely. Wish I could have given better feedback but just couldn't get through various errors even after following and retracing the steps in their docs.

marcospgp avatar Oct 04 '23 15:10 marcospgp

@marcospgp I use Unity 2021.3, Visual Studio Code 1.86.2 and Microsoft Unity Analyzers 1.15.0. Here is my current setup:

In the settings of Visual Studio Code Dotnet > Server: Use Omnisharp is set to true (because I still use Omnisharp and not C# DevKit). Next to the *.sln file of the Unity project there is a omnisharp.json file with the following content:

{
  "RoslynExtensionsOptions": {
    "EnableAnalyzersSupport": true,
    "LocationPaths": ["./NuGet/Microsoft.Unity.Analyzers"]
  }
}

In the path referenced by LocationPaths in the omnisharp.json file there is the file Microsoft.Unity.Analyzers.dll.

To get that dll file go to https://www.nuget.org/packages/Microsoft.Unity.Analyzers/ and on the right side click "Download package". You will get a file named microsoft.unity.analyzers.*.*.*.nupkg. Open that that file with your favorite archive application, for example 7-Zip. Within the archive in the folder analyzers\dotnet\cs\ there is the file Microsoft.Unity.Analyzers.dll. Extract it.

Both files, omnisharp.json and /NuGet/Microsoft.Unity.Analyzers/Microsoft.Unity.Analyzers.dll, are added to my repository (git).

PyrateAkananto avatar Mar 01 '24 12:03 PyrateAkananto

I use the omnisharp.json file to define the location of an RSP file to load an assembly, in a scripting project context (csx):

csx support is still an open issue, tracked here - https://github.com/dotnet/vscode-csharp/issues/6411 For the moment I would recommend sticking to O# for that.

@dibarbet This may be the only way to get analyzer nuget packages to work in a Unity project. There is a way to set up these DLLs as Unity assets (https://docs.unity3d.com/2023.3/Documentation/Manual/roslyn-analyzers.html) but I am not sure that it would result in those analyzers being reported in VSCode.

Supporting analyzers / code actions through direct dll references is something we will likely tackle at some point. That can be tracked here - https://github.com/dotnet/vscode-csharp/issues/6790

Going to close this issue - if there are other specific features that omnisharp.json supported that you would like to see, please file a new issue specifically for that feature. Its easier for us to track that way.

dibarbet avatar Mar 27 '24 23:03 dibarbet