hero image of How to use zed with dotnet (powered by omnisharp)

How to use zed with dotnet (powered by omnisharp)


Why Zed

I love Zed from day one. Recently I have been using my old laptop to code .NET & Astro.js for a project, but I have been frustrated by the fact that my laptop is not powerful enough to handle the load that made it freeze frequently due to OOM errors because of vscode. Tried to add more swap memory, it works and never faced OOM anymore but it burdens the CPU.

Did I tried Neovim? Yes, I tried Neovim, but it didn’t suit well me and it’s hard to set up. So, why Zed?

  • it’s fast
  • easy to use
  • feels like home (keymap vscode-ish)
  • support C# development with some juggling

Make Zed works well with .NET

Zed supports C# via csharp extension, but it needs some configuration and unfortunately it is not well documented. So, here is step by step how I configure it, but before we continue, I use linux mint here, so for other OS please adjust the steps by yourself:

  1. Install OmniSharp by yourself from here, then make OmniSharp executable by running chmod +x /path/to/OmniSharp
  2. Install the extension
  3. Add following configuration into settings.json
"lsp": {
"omnisharp": {
"binary": {
"path": "/path/to/OmniSharp",
"arguments": ["-lsp"]
}
}
}
  1. Run dotnet --info and see where it is installed in
Terminal window
/home/linuxbrew/.linuxbrew/Cellar/dotnet/9.0.6/libexec/sdk
  1. Find your libhostfxr.so is located, since my dotnet is located under /home/linuxbrew/.linuxbrew then I ran find /home/linuxbrew/.linuxbrew -name libhostfxr.so and make sure that you have the libhostfxr.so installed.
  2. Now that you found libhostfxr.so, add this into you bashrc or any other shell configuration file:
Terminal window
export DOTNET_ROOT=/home/linuxbrew/.linuxbrew/Cellar/dotnet/9.0.6/libexec #
export PATH=$DOTNET_ROOT:$PATH
  1. And finally, restart zed and enjoy!

Common Problems

Terminal window
The required library libhostfxr.so could not be found.
If this is a self-contained application, that library should exist in [/home/hndrbs/Codes/Omnisharp/]

Your DOTNET_ROOT in your shell configuration file might be incorrect.

Terminal window
Language server omnisharp:
failed to spawn command. path: "<OmniSharp path>", working directory: "<workdir>", args: ["optional", "additional", "args", "-lsp"]
-- stderr--

Your lsp.omnisharp.binary.path in settings.json might be incorrect, make sure you typed full path and remember that path is case sensitive.

Terminal window
System.InvalidOperationException: Enumeration already finished.
at System.SZGenericArrayEnumerator`1.get_Current()
at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.CommandArgumentEnumerator.get_Current()
at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.CommandArgumentEnumerator.MoveNext()
at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessCommandOrParameter(CommandOrParameterArgument arg)
at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessNext()
at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.Process()
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Parse(String[] args)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at OmniSharp.CommandLineApplication.Execute(String[] args) in /home/vsts/work/1/s/src/OmniSharp.Host/CommandLineApplication.cs:line 65
at OmniSharp.Stdio.Driver.Program.<>c__DisplayClass0_0.<Main>b__0() in /home/vsts/work/1/s/src/OmniSharp.Stdio.Driver/Program.cs:line 84
at OmniSharp.HostHelpers.Start(Func`1 action) in /home/vsts/work/1/s/src/OmniSharp.Host/HostHelpers.cs:line 30

your args must be ["-lsp"] only, even though in zed docs it should be ["optional", "additional", "args", "-lsp"]

Still facing a problem? please hit me up through my linkedin, will be gladly to help you out.